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

Commit be6ab039 by Sascha Depold

fixed bug with cross associated tables

1 parent da77d30d
...@@ -22,17 +22,25 @@ SequelizeTable = function(sequelize, tableName, attributes) { ...@@ -22,17 +22,25 @@ SequelizeTable = function(sequelize, tableName, attributes) {
attributes: attributes, attributes: attributes,
tableName: tableName, tableName: tableName,
isCrossAssociatedWith: function(associatedTable) { isAssociatedWith: function(anotherTable, associationType) {
var result = false var result = false
var myTableName = table.tableName
associatedTable.associations.forEach(function(association) { var associations = SequelizeHelper.Array.select(table.associations, function(assoc) {
if((association.table.tableName == myTableName) && (association.type == 'hasMany')) return assoc.table.tableName == anotherTable.tableName
result = true
}) })
if(associations.length > 0) {
if(associationType) result = (associations[0].type == associationType)
else result = true
}
return result return result
}, },
isCrossAssociatedWith: function(anotherTable) {
return table.isAssociatedWith(anotherTable, 'hasMany') && anotherTable.isAssociatedWith(table, 'hasMany')
},
prepareAssociations: function(callback) { prepareAssociations: function(callback) {
table.associations.forEach(function(association) { table.associations.forEach(function(association) {
switch(association.type) { switch(association.type) {
......
...@@ -218,7 +218,6 @@ module.exports = { ...@@ -218,7 +218,6 @@ module.exports = {
var task = new Task({ title:'do smth' }) var task = new Task({ title:'do smth' })
var deadline = new Deadline({date: new Date()}) var deadline = new Deadline({date: new Date()})
var assertMe = null
Sequelize.chainQueries([{drop: s2}, {sync: s2}], function() { Sequelize.chainQueries([{drop: s2}, {sync: s2}], function() {
task.save(function() { task.save(function() {
...@@ -292,5 +291,15 @@ module.exports = { ...@@ -292,5 +291,15 @@ module.exports = {
beforeExit(function() { beforeExit(function() {
assert.isNull(subject) assert.isNull(subject)
}) })
},
'isAssociatedWith': function(assert, beforeExit) {
var IsAssociatedWithTestOne = s.define("IsAssociatedWithTestOne", {})
var IsAssociatedWithTestTwo = s.define("IsAssociatedWithTestTwo", {})
IsAssociatedWithTestOne.belongsTo('foo', IsAssociatedWithTestTwo)
assert.equal(true, IsAssociatedWithTestOne.isAssociatedWith(IsAssociatedWithTestTwo))
assert.equal(true, IsAssociatedWithTestOne.isAssociatedWith(IsAssociatedWithTestTwo, 'belongsTo'))
assert.equal(false, IsAssociatedWithTestOne.isAssociatedWith(IsAssociatedWithTestTwo, 'hasMany'))
assert.equal(false, IsAssociatedWithTestOne.isAssociatedWith(IsAssociatedWithTestTwo, 'hasOne'))
} }
} }
\ 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!