Skip to content

Commit

Permalink
Fix hasmany 'has' accessor to work with custom keys
Browse files Browse the repository at this point in the history
  • Loading branch information
dxg committed Dec 19, 2016
1 parent 1119ad2 commit 71f3e73
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### v3.2.2
- Fix the fix in [#761](../../issues/761) so that it works with custom keys ([#762](../../issues/762))

### v3.2.1
- Fix has many 'has' accessor failing when join table has duplicate entries ([#761](../../issues/761))

Expand Down
12 changes: 9 additions & 3 deletions lib/Associations/Many.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,16 @@ function extendInstance(Model, Instance, Driver, association, opts, createInstan
if (err) return cb(err);
if (_.isEmpty(Instances)) return cb(null, false);

var foundItemsIDs = _(foundItems).map('id').uniq().value();
var InstancesIDs = _(Instances ).map('id').uniq().value();
var mapKeysToString = function (item) {
return _.map(association.model.keys, function (k) {
return item[k];
}).join(',')
}

var foundItemsIDs = _(foundItems).map(mapKeysToString).uniq().value();
var InstancesIDs = _(Instances ).map(mapKeysToString).uniq().value();

var sameLength = foundItemsIDs.length == InstancesIDs.length;
var sameLength = foundItemsIDs.length == InstancesIDs.length;
var sameContents = sameLength && _.isEmpty(_.difference(foundItemsIDs, InstancesIDs));

return cb(null, sameContents);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"sqlite",
"mongodb"
],
"version" : "3.2.1",
"version" : "3.2.2",
"license" : "MIT",
"homepage" : "http://dresende.github.io/node-orm2",
"repository" : "http://github.com/dresende/node-orm2.git",
Expand Down

0 comments on commit 71f3e73

Please sign in to comment.