Skip to content

Commit 5bc03c3

Browse files
committed
0.2.1
1 parent 4fa15b7 commit 5bc03c3

File tree

5 files changed

+49
-22
lines changed

5 files changed

+49
-22
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
##### 0.2.1 - 10 March 2016
2+
3+
Fix for localKeys
4+
15
##### 0.2.0 - 10 March 2016
26

37
Pulled a lot more common adapter functionality into js-data-adapter.

dist/js-data-adapter.js

Lines changed: 23 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js-data-adapter.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "js-data-adapter",
33
"description": "Base adapter class that all other js-data adapters extend.",
4-
"version": "0.2.0",
4+
"version": "0.2.1",
55
"homepage": "https://github.com/js-data/js-data-adapter",
66
"repository": {
77
"type": "git",

src/index.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,23 @@ addHiddenPropsToTarget(Adapter.prototype, {
706706
return def.getForeignKey(record)
707707
},
708708

709+
/**
710+
* Return the localKeys from the given record for the provided relationship.
711+
*
712+
* Override with care.
713+
*
714+
* @name Adapter#makeHasManyLocalKeys
715+
* @method
716+
* @return {*}
717+
*/
718+
makeHasManyLocalKeys (mapper, def, record) {
719+
let localKeys = []
720+
let itemKeys = get(record, def.localKeys) || []
721+
itemKeys = isArray(itemKeys) ? itemKeys : Object.keys(itemKeys)
722+
localKeys = localKeys.concat(itemKeys)
723+
return unique(localKeys).filter(function (x) { return x })
724+
},
725+
709726
/**
710727
* Return the foreignKeys from the given record for the provided relationship.
711728
*
@@ -779,25 +796,19 @@ addHiddenPropsToTarget(Adapter.prototype, {
779796
}
780797

781798
if (record) {
782-
let localKeys = []
783-
let itemKeys = get(record, def.localKeys) || []
784-
itemKeys = isArray(itemKeys) ? itemKeys : Object.keys(itemKeys)
785-
localKeys = localKeys.concat(itemKeys)
786799
return self.findAll(relatedMapper, {
787800
where: {
788801
[relatedMapper.idAttribute]: {
789-
'in': unique(localKeys).filter(function (x) { return x })
802+
'in': self.makeHasManyLocalKeys(mapper, def, record)
790803
}
791804
}
792805
}, __opts).then(function (relatedItems) {
793806
def.setLocalField(record, relatedItems)
794807
})
795808
} else {
796809
let localKeys = []
797-
records.forEach(function (item) {
798-
let itemKeys = item[def.localKeys] || []
799-
itemKeys = isArray(itemKeys) ? itemKeys : Object.keys(itemKeys)
800-
localKeys = localKeys.concat(itemKeys)
810+
records.forEach(function (record) {
811+
localKeys = localKeys.concat(self.self.makeHasManyLocalKeys(mapper, def, record))
801812
})
802813
return self.findAll(relatedMapper, {
803814
where: {

0 commit comments

Comments
 (0)