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.