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

Commit 66d899a7 by Sascha Depold

associatedData => fetchedAssociations

1 parent cece3d69
...@@ -21,7 +21,7 @@ Sequelize.chainQueries([{drop: sequelize}, {sync: sequelize}], function() { ...@@ -21,7 +21,7 @@ Sequelize.chainQueries([{drop: sequelize}, {sync: sequelize}], function() {
console.log("Now let's get the same data with loadAssociatedData!") console.log("Now let's get the same data with loadAssociatedData!")
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.associatedData.pets[0].name) Sequelize.Helper.log("The object should now also contain the data: " + person.fetchedAssociations.pets[0].name)
Person.find(person.id, { fetchAssociations: true }, function(p) { Person.find(person.id, { fetchAssociations: true }, function(p) {
Sequelize.Helper.log(p) Sequelize.Helper.log(p)
......
...@@ -36,6 +36,7 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o ...@@ -36,6 +36,7 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
this.id = null // specify id as null to declare this object as unsaved and as not present in the database this.id = null // specify id as null to declare this object as unsaved and as not present in the database
this.table = table this.table = table
this.fetchedAssociations = {}
} }
// class methods // class methods
...@@ -304,8 +305,8 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o ...@@ -304,8 +305,8 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
var associatedData = {}, var associatedData = {},
self = this, self = this,
setAssociatedDataAndReturn = function() { setAssociatedDataAndReturn = function() {
self.associatedData = associatedData self.fetchedAssociations = associatedData
if(callback) callback(associatedData) if(callback) callback(self.fetchedAssociations)
} }
if(this.table.associations.length == 0) if(this.table.associations.length == 0)
...@@ -323,6 +324,10 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o ...@@ -323,6 +324,10 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
}) })
}, },
hasFetchedAssociationFor: function(assocName) {
return this.fetchedAssociations && this.fetchedAssociations[assocName]
},
save: function(callback) { save: function(callback) {
var query = null, var query = null,
self = this self = this
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!