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

Commit 7eeccd0c by Sascha Depold

some changes on the example

1 parent 8f0763a1
Showing with 27 additions and 14 deletions
......@@ -16,37 +16,50 @@ Sequelize.chainQueries([{drop: sequelize}, {sync: sequelize}], function() {
pet1 = new Pet({ name: 'Bob' }),
pet2 = new Pet({ name: 'Aaron' })
Sequelize.chainQueries([{save: person}, {save: pet1}, {save: pet2], function() {
Sequelize.chainQueries([{save: person}, {save: pet1}, {save: pet2}], function() {
person.setPets([pet1], function(pets) {
console.log('my pet: ' + pets[0].name )
console.log("Now let's get the same data with fetchData!")
Sequelize.Helper.log('my pet: ' + pets[0].name )
Sequelize.Helper.log("Now let's get the same data with fetchData!")
person.fetchAssociations(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.fetchedAssociations.pets[0].name)
Sequelize.Helper.log('This should do a database request!')
Sequelize.Helper.log('This won\'t 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...")
person.setPets([pet1, pet2], function() {
Sequelize.Helper.log("The set call has stored the pets as associated data!")
Sequelize.Helper.log("And now let's find the pets again! This will make no new database request but serve the already stored pets Bob and Aaron!")
Sequelize.Helper.log('This should do no database request and just serves the already received pets')
person.getPets(function(pets) {
person.getPets(function(pets) {
})
})
Sequelize.Helper.log("Pets: " + pets.map(function(pet) { return pet.name }).join(", "))
Sequelize.Helper.log("Now let's force the reloading of pets!")
person.getPets({refetchAssociations: true}, function(pets) {
Person.find(person.id, { fetchAssociations: true }, function(p) {
Sequelize.Helper.log('Works with find as well: ' + p.fetchedAssociations.pets[0].name)
})
Sequelize.Helper.log("Pets: " + pets.map(function(pet) { return pet.name }).join(", "))
Person.findAll({ fetchAssociations: true }, function(people) {
Sequelize.Helper.log('And also with findAll:' + people[0].fetchedAssociations.pets[0].name)
})
Person.find(person.id, { fetchAssociations: true }, function(p) {
var petNames = p.fetchedAssociations.pets.map(function(pet) { return pet.name }).join(", ")
Sequelize.Helper.log('Works with find as well: ' + petNames)
})
Person.findAll({ fetchAssociations: true }, function(people) {
var petNames = people[0].fetchedAssociations.pets.map(function(pet) { return pet.name }).join(", ")
Sequelize.Helper.log('And also with findAll: ' + petNames)
})
})
})
})
})
})
})
})
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!