不要怂,就是干,撸起袖子干!

Commit fff633bb by Sascha Depold

new example for associations

1 parent 718aa4d6
Showing with 6 additions and 3 deletions
...@@ -24,13 +24,15 @@ Sequelize.chainQueries([{drop: sequelize}, {sync: sequelize}], function() { ...@@ -24,13 +24,15 @@ Sequelize.chainQueries([{drop: sequelize}, {sync: sequelize}], function() {
var person = new Person({ name: 'Luke' }), var person = new Person({ name: 'Luke' }),
mother = new Person({ name: 'Jane' }), mother = new Person({ name: 'Jane' }),
father = new Person({ name: 'John' }), father = new Person({ name: 'John' }),
brother = new Person({ name: 'brother' }), brother = new Person({ name: 'Brother' }),
sister = new Person({ name: 'sister' }) sister = new Person({ name: 'Sister' }),
pet = new Pet({ name: 'Bob' })
Sequelize.chainQueries([{save: person}, {save: mother}, {save: father}, {save: brother}, {save: sister}], function() { Sequelize.chainQueries([{save: person}, {save: mother}, {save: father}, {save: brother}, {save: sister}, {save: pet}], function() {
person.setMother(mother, function(mom) { Sequelize.Helper.log('my mom: ' + mom.name) }) person.setMother(mother, function(mom) { Sequelize.Helper.log('my mom: ' + mom.name) })
person.setFather(father, function(dad) { Sequelize.Helper.log('my dad: ' + dad.name) }) person.setFather(father, function(dad) { Sequelize.Helper.log('my dad: ' + dad.name) })
/*person.setBrothers([brother], function(bros) { Sequelize.Helper.log('ma bro: ' + bros[0].name)}) /*person.setBrothers([brother], function(bros) { Sequelize.Helper.log('ma bro: ' + bros[0].name)})
person.setSisters([sister], function(sis) { Sequelize.Helper.log('ma sis\': ' + sis[0].name)})*/ person.setSisters([sister], function(sis) { Sequelize.Helper.log('ma sis\': ' + sis[0].name)})*/
person.setPets([pet], function(pets) { Sequelize.Helper.log('my pet: ' + pets[0].name )})
}) })
}) })
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!