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

Commit 5c1ea45c by Sascha Depold

example for loading associations

1 parent c7592d70
Showing with 29 additions and 0 deletions
var Sequelize = require(__dirname + "/../../lib/sequelize/Sequelize").Sequelize,
sequelize = new Sequelize("sequelize_test", "root", null, {disableLogging: false})
var Person = sequelize.define('person', {
name: Sequelize.STRING
})
var Pet = sequelize.define('pet', {
name: Sequelize.STRING
})
Person.hasManyAndBelongsTo('pets', Pet, 'owner')
Sequelize.chainQueries([{drop: sequelize}, {sync: sequelize}], function() {
var person = new Person({ name: 'Luke' }),
pet = new Pet({ name: 'Bob' })
Sequelize.chainQueries([{save: person}, {save: pet}], function() {
person.setPets([pet], function(pets) {
console.log('my pet: ' + pets[0].name )
console.log("Now let's get the same data with loadAssociatedData!")
person.loadAssociatedData(function(data) {
Sequelize.Helper.log("And here we are: " + data.pets[0].name)
Sequelize.Helper.log("The object should now also contain the data: " + person.associatedData.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!