Permalink
Browse files

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

  • Loading branch information...
1 parent 3a732cc commit 14bd23bf00a104bdc1dad3c5294b54a9c362d7ba @1602 committed Apr 13, 2013
Showing with 6 additions and 5 deletions.
  1. +1 −1 docs/model.md
  2. +5 −2 lib/relations.js
  3. +0 −2 test/relations.test.js
View
@@ -181,7 +181,7 @@ TODO: document
### hasAndBelongsToMany
-TODO: implement and document
+TODO: document
## SEE ALSO
View
@@ -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) {
@@ -229,8 +229,6 @@ describe('relations', function() {
});
});
- it('should allow to destroy instance and connection');
-
});
});

0 comments on commit 14bd23b

Please sign in to comment.