When a required number property is set to NaN, for example as a result
of coersion (`Number([1,2,3])`), the "presence" validation now correctly
reports an error.
Fix the implementation of updateOrCreate (a.k.a. upsert) to validate
the model before calling the connector.
In order to preserve backwards compatibility, validation errors are
only logged via console.warn by default.
The correct behaviour, where validation errors fail the updateOrCreate
operation, can be enabled via new model setting "validateUpsert".
When a callback is omitted from a method on a model relation that
supports promises, return that promise. This includes all the standard
DAO methods, as well as any user-defined methods that return promises.
e.g.:
mylist.todos.create({name: 'Item 1'}) // returns Promise
This API will use native ES6 promises if available. If not available,
or to force the use of another Promise library, you must assign the
global.Promise object.
e.g.:
global.Promise = require('bluebird')
Relations affected:
- BelongsTo
- HasOne
- HasMany
- HasManyThrough
- HasAndBelongsToMany
- ReferencesMany
- EmbedsOne
Exceptions:
The EmbedsMany relation has not been promisified, because most of the
methods return synchronous values.
The base relation getter method [e.g.: mylist.todos()] has not been
promisified, due to its default caching behavior.
New Methods:
- getAsync(condition, cb)
A new method "getAsync()" has been added to all relations except
EmbedsMany, which always fetches from the datasource rather than from
the cache. It takes an optional "where" condition (except for HasOne
and BelongsTo) and an optional callback. If the callback is omitted,
a Promise is returned.
* Fix test for "after save" called on save/CREATE (Miroslav Bajtoš)
* Code cleanup in lib/dao.js (Miroslav Bajtoš)
* Save parent model of embedded relations (Fabien Franzen)
* Pass options in operation hooks context. (Fabien Franzen)
* check if id does not exist a bit more explicitly (Pulkit Singhal)
* Fix persistUndefinedAsNull tests w/ SQL connectors (Miroslav Bajtoš)
* Implement scope.updateAll (Fabien Franzen)
* Fix the test cases so that they be run with the mssql connector (Raymond Feng)
* Add model setting "persistUndefinedAsNull" (Miroslav Bajtoš)
* Add abilities to remove and clear observers - Operation Hooks. (0angelic0)
When the setting "persistUndefinedAsNull" is true,
the model will use `null` instead of `undefined` in
all property values.
- Known optional model properties are set to `null` when no value
was provided.
- When setting model properties, `undefined` is always converted
to `null`. This applies to both known (model-defined) properties
and additional (custom, dynamic) properties.
- The instance method `toObject()` converts `undefined` to `null` too.
Because `toJSON()` calls `toObject()` under the hood, the change
applies to `toJSON()` too.
* Code cleanup in updateAll/deleteAll (Miroslav Bajtoš)
* Return scope object from DAO.scope (Fabien Franzen)
* Remove all usages of lodash. (Miroslav Bajtoš)
* Clean up delete and update tests (Simon Ho)
* Clean up wording in update/delete tests (Simon Ho)
* Fix wording in update test (Simon Ho)
* Properly support embedsMany destroyAll (Fabien Franzen)
* Clean up update/delete manipulation tests (Simon Ho)
* test: fix test failure in MySQL connector (Miroslav Bajtoš)
* Improve test failure messages (Miroslav Bajtoš)
* Fix regression in prototype.save (Miroslav Bajtoš)
* Enable more CRUD remoting methods for embedsOne (Fabien Franzen)
* Implement scope.findOne (Fabien Franzen)
* use findOrCreate for HasManyThrough#create (Clark Wang)
* Enhance id comparision for updateAttributes (Raymond Feng)
* Enable custom methods on singular relations (Fabien Franzen)
* Implement scope.findById (Fabien Franzen)
* Fix updateAll callback in "transient" connector (Miroslav Bajtoš)
* Memory connector returns updated records count (Simon Ho)
* Add ctx.isNewInstance for "save" hooks (Miroslav Bajtoš)
* deleteAll returns number of deleted records (Miroslav Bajtoš)
* Use the correct way to iterate over an array (Raymond Feng)
* DAO: Fix updateOrCreate to set persisted:true (Miroslav Bajtoš)
* Reject CREATE with a duplicate id (Miroslav Bajtoš)
* add tests for between in memory connector (Daniel B. Vasquez)
* enable between filter for memory db connector (Daniel B. Vasquez)
* fix#429 Multiple Models can't mixin same class (Clark Wang)
Rename the second callback argument to `info` to make its purpose more
clear. Fix jsdoc comments, note that these comments are NOT shown
on http://apidocs.strongloop.com/.