Skip to content

Fix hasmany 'has' accessor to work with custom keys #762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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