objection
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -1206,5 +1206,29 @@ 'use strict'; | ||
return builder.insert(json).returning(ModelClass.idColumn).runAfterModelCreatePushFront(function (ids) { | ||
_.each(models, function (model, idx) { | ||
model.$id(ids[idx]); | ||
if (!builder.has('returning')) { | ||
// If the user hasn't specified a `returning` clause, we make sure | ||
// that at least the identifier is returned. | ||
builder.returning(ModelClass.idColumn); | ||
} | ||
return builder.insert(json).runAfterModelCreatePushFront(function (ret) { | ||
// If the user specified a `returning` clause the result may already be | ||
// an array of models. | ||
if (!_.isEmpty(ret) && _.isObject(ret[0])) { | ||
_.each(models, function (model, index) { | ||
model.$set(ret[index]); | ||
// The returning clause must return at least the identifier. | ||
if (!model.$id()) { | ||
throw new Error('the identifier column "' + ModelClass.idColumn + '"' + | ||
' must be listed in the `returning` clause. (`returning *` is fine also)'); | ||
} | ||
}); | ||
} else { | ||
// If the return value is not an array of models, it is an array of identifiers. | ||
_.each(models, function (model, idx) { | ||
model.$id(ret[idx]); | ||
}); | ||
} | ||
_.each(models, function (model) { | ||
model.$afterInsert(); | ||
@@ -1211,0 +1235,0 @@ }); |
@@ -338,7 +338,3 @@ "use strict"; | ||
for (var key in json) { | ||
if (ModelClass.hasOwnJsonProperty(json, key)) { | ||
this[key] = json[key]; | ||
} | ||
} | ||
this.$set(json); | ||
}; | ||
@@ -356,9 +352,23 @@ | ||
json = this.$parseDatabaseJson(json || {}); | ||
this.$set(json); | ||
}; | ||
/** | ||
* Sets the values from another model or object. | ||
* | ||
* Unlike $setJson, this doesn't call any `$parseJson` methods or validate the input. | ||
* This simply sets each value in the object to this object. | ||
* | ||
* @param {Object} obj | ||
*/ | ||
ModelBase.prototype.$set = function (obj) { | ||
var ModelClass = this.constructor; | ||
for (var key in json) { | ||
if (ModelClass.hasOwnJsonProperty(json, key)) { | ||
this[key] = json[key]; | ||
for (var key in obj) { | ||
if (ModelClass.hasOwnJsonProperty(obj, key)) { | ||
this[key] = obj[key]; | ||
} | ||
} | ||
return this; | ||
}; | ||
@@ -365,0 +375,0 @@ |
{ | ||
"name": "objection", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "An SQL-friendly ORM for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "objection.js", |
@@ -1,2 +0,2 @@ | ||
[![Build Status](https://travis-ci.org/Vincit/objection.js.svg?branch=master)](https://travis-ci.org/Vincit/objection.js) [![Coverage Status](https://coveralls.io/repos/Vincit/objection.js/badge.svg)](https://coveralls.io/r/Vincit/objection.js) | ||
[![Build Status](https://travis-ci.org/Vincit/objection.js.svg?branch=master)](https://travis-ci.org/Vincit/objection.js) [![Coverage Status](https://coveralls.io/repos/Vincit/objection.js/badge.svg?branch=master&service=github)](https://coveralls.io/github/Vincit/objection.js?branch=master) | ||
@@ -655,3 +655,3 @@ # Introduction | ||
### New features | ||
### What's new | ||
@@ -658,0 +658,0 @@ * New name `objection.js`. |
205928
5997