Skip to content

Commit

Permalink
Stable Version 0.11.8
Browse files Browse the repository at this point in the history
  • Loading branch information
techniq committed Jan 19, 2016
1 parent f4352e7 commit c55e292
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
46 changes: 27 additions & 19 deletions dist/js-data-sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,29 +232,35 @@ module.exports =
})();
} else if (def.type === 'belongsTo' || def.type === 'hasOne' && def.localKey) {
if (instance) {
task = _this.find(resourceConfig.getResource(relationName), DSUtils.get(instance, def.localKey), __options).then(function (relatedItem) {
instance[def.localField] = relatedItem;
return relatedItem;
});
var id = DSUtils.get(instance, def.localKey);
if (id) {
task = _this.find(resourceConfig.getResource(relationName), DSUtils.get(instance, def.localKey), __options).then(function (relatedItem) {
instance[def.localField] = relatedItem;
return relatedItem;
});
}
} else {
task = _this.findAll(resourceConfig.getResource(relationName), {
where: _defineProperty({}, relationDef.idAttribute, {
'in': DSUtils.filter(items.map(function (item) {
return DSUtils.get(item, def.localKey);
}), function (x) {
return x;
var ids = DSUtils.filter(items.map(function (item) {
return DSUtils.get(item, def.localKey);
}), function (x) {
return x;
});
if (ids.length) {
task = _this.findAll(resourceConfig.getResource(relationName), {
where: _defineProperty({}, relationDef.idAttribute, {
'in': ids
})
})
}, __options).then(function (relatedItems) {
DSUtils.forEach(items, function (item) {
DSUtils.forEach(relatedItems, function (relatedItem) {
if (relatedItem[relationDef.idAttribute] === item[def.localKey]) {
item[def.localField] = relatedItem;
}
}, __options).then(function (relatedItems) {
DSUtils.forEach(items, function (item) {
DSUtils.forEach(relatedItems, function (relatedItem) {
if (relatedItem[relationDef.idAttribute] === item[def.localKey]) {
item[def.localField] = relatedItem;
}
});
});
return relatedItems;
});
return relatedItems;
});
}
}
}

Expand Down Expand Up @@ -503,6 +509,8 @@ module.exports =
}
} else if (op === 'like') {
query = query.where(field, 'like', v);
} else if (op === '|like') {
query = query.orWhere(field, 'like', v);
} else if (op === '|==' || op === '|===') {
if (v === null) {
query = query.orWhereNull(field);
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.7",
"version": "0.11.8",
"homepage": "http://www.js-data.io/docs/dssqladapter",
"repository": {
"type": "git",
Expand Down

0 comments on commit c55e292

Please sign in to comment.