Fix m2m: only add fk when hasMany have no "through"

This commit is contained in:
Anatoliy Chakkaev 2013-04-13 05:35:53 +04:00 committed by Raymond Feng
parent fad77ed963
commit a73f53521e
3 changed files with 6 additions and 5 deletions

View File

@ -181,7 +181,7 @@ TODO: document
### hasAndBelongsToMany
TODO: implement and document
TODO: document
## SEE ALSO

View File

@ -94,6 +94,7 @@ Model.hasMany = function hasMany(anotherClass, params) {
d.destroy(done);
});
};
delete scopeMethods.destroy;
}
defineScope(this.prototype, params.through || anotherClass, methodName, function () {
var filter = {};
@ -106,8 +107,10 @@ Model.hasMany = function hasMany(anotherClass, params) {
return filter;
}, scopeMethods);
// obviously, anotherClass should have attribute called `fk`
anotherClass.schema.defineForeignKey(anotherClass.modelName, fk);
if (!params.through) {
// obviously, anotherClass should have attribute called `fk`
anotherClass.schema.defineForeignKey(anotherClass.modelName, fk);
}
function find(id, cb) {
anotherClass.find(id, function (err, inst) {

View File

@ -229,8 +229,6 @@ describe('relations', function() {
});
});
it('should allow to destroy instance and connection');
});
});