Fix m2m: only add fk when hasMany have no "through"
This commit is contained in:
parent
fad77ed963
commit
a73f53521e
|
@ -181,7 +181,7 @@ TODO: document
|
|||
|
||||
### hasAndBelongsToMany
|
||||
|
||||
TODO: implement and document
|
||||
TODO: document
|
||||
|
||||
## SEE ALSO
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
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) {
|
||||
|
|
|
@ -229,8 +229,6 @@ describe('relations', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should allow to destroy instance and connection');
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue