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

Commit 8f0763a1 by Sascha Depold

renamed example folder

1 parent 66d899a7
...@@ -13,23 +13,40 @@ Person.hasManyAndBelongsTo('pets', Pet, 'owner') ...@@ -13,23 +13,40 @@ Person.hasManyAndBelongsTo('pets', Pet, 'owner')
Sequelize.chainQueries([{drop: sequelize}, {sync: sequelize}], function() { Sequelize.chainQueries([{drop: sequelize}, {sync: sequelize}], function() {
var person = new Person({ name: 'Luke' }), var person = new Person({ name: 'Luke' }),
pet = new Pet({ name: 'Bob' }) pet1 = new Pet({ name: 'Bob' }),
pet2 = new Pet({ name: 'Aaron' })
Sequelize.chainQueries([{save: person}, {save: pet}], function() { Sequelize.chainQueries([{save: person}, {save: pet1}, {save: pet2], function() {
person.setPets([pet], function(pets) { person.setPets([pet1], function(pets) {
console.log('my pet: ' + pets[0].name ) console.log('my pet: ' + pets[0].name )
console.log("Now let's get the same data with loadAssociatedData!") console.log("Now let's get the same data with fetchData!")
person.fetchAssociations(function(data) { person.fetchAssociations(function(data) {
Sequelize.Helper.log("And here we are: " + data.pets[0].name) Sequelize.Helper.log("And here we are: " + data.pets[0].name)
Sequelize.Helper.log("The object should now also contain the data: " + person.fetchedAssociations.pets[0].name) Sequelize.Helper.log("The object should now also contain the data: " + person.fetchedAssociations.pets[0].name)
Sequelize.Helper.log('This should do a database request!')
person.getPets(function(pets) {
Sequelize.Helper.log("Pets: " + pets.map(function(pet) { return pet.name }).join(", "))
Sequelize.Helper.log("Let's associate with another pet...")
Sequelize.Helper.log('This should do no database request and just serves the already received pets')
person.getPets(function(pets) {
})
})
Person.find(person.id, { fetchAssociations: true }, function(p) { Person.find(person.id, { fetchAssociations: true }, function(p) {
Sequelize.Helper.log(p) Sequelize.Helper.log('Works with find as well: ' + p.fetchedAssociations.pets[0].name)
}) })
Person.findAll({ fetchAssociations: true }, function(people) { Person.findAll({ fetchAssociations: true }, function(people) {
Sequelize.Helper.log(people) Sequelize.Helper.log('And also with findAll:' + people[0].fetchedAssociations.pets[0].name)
}) })
}) })
}) })
}) })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!