Skip to content

Commit

Permalink
Stable Version 0.11.13
Browse files Browse the repository at this point in the history
  • Loading branch information
techniq committed Mar 11, 2016
1 parent 1f4f2bf commit 6fefdff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions dist/js-data-sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ module.exports =

if ((def.type === 'hasOne' || def.type === 'hasMany') && def.foreignKey) {
task = _this.findAll(resourceConfig.getResource(relationName), {
where: _defineProperty({}, def.foreignKey, instance ? { '==': instance[resourceConfig.idAttribute] } : { 'in': items.map(function (item) {
return item[resourceConfig.idAttribute];
where: _defineProperty({}, def.foreignKey, instance ? { '==': instance[def.localKey || resourceConfig.idAttribute] } : { 'in': items.map(function (item) {
return item[def.localKey || resourceConfig.idAttribute];
}) })
}, __options).then(function (relatedItems) {
if (instance) {
Expand All @@ -129,7 +129,7 @@ module.exports =
} else {
items.forEach(function (item) {
var attached = relatedItems.filter(function (ri) {
return ri[def.foreignKey] === item[resourceConfig.idAttribute];
return ri[def.foreignKey] === item[def.localKey || resourceConfig.idAttribute];
});
if (def.type === 'hasOne' && attached.length) {
item[def.localField] = attached[0];
Expand Down Expand Up @@ -184,7 +184,10 @@ module.exports =
if (instance) {
var id = (0, _object.get)(instance, def.localKey);
if (id) {
task = _this.find(resourceConfig.getResource(relationName), (0, _object.get)(instance, def.localKey), __options).then(function (relatedItem) {
task = _this.findAll(resourceConfig.getResource(relationName), {
where: _defineProperty({}, def.foreignKey || relationDef.idAttribute, { '==': id })
}, __options).then(function (relatedItems) {
var relatedItem = relatedItems && relatedItems[0];
instance[def.localField] = relatedItem;
return relatedItem;
});
Expand All @@ -197,13 +200,11 @@ module.exports =
});
if (ids.length) {
task = _this.findAll(resourceConfig.getResource(relationName), {
where: _defineProperty({}, relationDef.idAttribute, {
'in': ids
})
where: _defineProperty({}, def.foreignKey || relationDef.idAttribute, { 'in': ids })
}, __options).then(function (relatedItems) {
items.forEach(function (item) {
relatedItems.forEach(function (relatedItem) {
if (relatedItem[relationDef.idAttribute] === item[def.localKey]) {
if (relatedItem[def.foreignKey || relationDef.idAttribute] === item[def.localKey]) {
item[def.localField] = relatedItem;
}
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "js-data-sql",
"description": "Postgres/MySQL/MariaDB/SQLite3 adapter for js-data.",
"version": "0.11.12",
"version": "0.11.13",
"homepage": "http://www.js-data.io/docs/dssqladapter",
"repository": {
"type": "git",
Expand Down

0 comments on commit 6fefdff

Please sign in to comment.