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

Commit be6ab039 by Sascha Depold

fixed bug with cross associated tables

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