From ec8cac4d3802f7e2e65e9b4f95dc791ac9a6ec2d Mon Sep 17 00:00:00 2001 From: Philipp Waldmann Date: Thu, 10 Jul 2014 16:04:11 +0200 Subject: [PATCH] Include with asJson bugfix --- lib/persistence/include.js | 9 +++++++-- lib/stores/sql/save.js | 2 +- package.json | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/persistence/include.js b/lib/persistence/include.js index 86f11a79..c9a5974d 100644 --- a/lib/persistence/include.js +++ b/lib/persistence/include.js @@ -256,6 +256,7 @@ exports.definition = { var records = base.records[n][sub_records[i][relation.foreign_key]]; for(var r in records){ if(base.as && base.take){ + //TODO: check relation type as well (see below..) records[r][base.as] = records[r][base.as] || []; var sr = sub_records[i][base.take[0]]; @@ -264,8 +265,12 @@ exports.definition = { } records[r][base.as].push(sr); }else{ - records[r][relation.name] = records[r][relation.name] || []; - records[r][relation.name].push(sub_records[i]); + if(base.relation.type === 'has_many'){ + records[r][relation.name] = records[r][relation.name] || []; + records[r][relation.name].push(sub_records[i]); + }else{ + records[r][relation.name] = records[r][relation.name] || sub_records[i]; + } } } } diff --git a/lib/stores/sql/save.js b/lib/stores/sql/save.js index 9c26c725..431b9f3a 100644 --- a/lib/stores/sql/save.js +++ b/lib/stores/sql/save.js @@ -248,7 +248,7 @@ exports.model = { * @param {integer} affected_records - The number of affected records * @this Collection * - * @return {Model} + * @return {Promise} */ update: function(attributes, options, resolve, reject){ return this.updateAll(attributes, options, resolve, reject); diff --git a/package.json b/package.json index dfcfc216..d51dab49 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "openrecord", - "version": "1.1.0", + "version": "1.1.1", "description": "Active record like ORM for nodejs", "keywords": ["orm", "record", "sql", "sqlite3", "postgres", "pg", "mysql", "database", "activerecord", "promise", "rest", "restify", "nested set"], "author": "Philipp Waldmann ",