Before this commit, the following code would not work:
Change.updateOrCreate({...}, function(err, ch) {
// somewhere later, modify "ch" and save the changes
ch.save(cb);
});
"before delete" and "after delete" hooks receive `ctx.instance`
when a single model is being deleted.
"before save" hook receives `ctx.currentInstance` when triggered
by `prototype.updateAttributes()`.
Note that "after save" hook triggered by `prototype.updateAttributes()`
already provides `ctx.instance`.
* Improved and corrected API docs (crandmck)
* Fix problems in annotations that prvented validateAsync and validate functions from appearing in API docs. (crandmck)
* Deprecate DAO events (Miroslav Bajtoš)
* Deprecate Model hooks (Miroslav Bajtoš)
* Add Promises to DAO (Partap Davis)
* test for updateAll (rudzon)
* enhance the coercion for boolean/date types (rudzon)
* enhance updateAll to coerce the data per property definitions (rudzon)
* relation-definition: remove trailing whitespace (Miroslav Bajtoš)
List of deprecated hooks:
- beforeValidate
- afterValidate
- beforeCreate
- afterCreate
- beforeSave
- afterSave
- beforeUpdate
- afterUpdate
- beforeDestroy
- afterDestroy
Also add a lightweight browser version of "depd", because the "depd"
does not support browser and it is not trivial to fix that.
This commits adds a lightweight implementation of depd's "deprecate"
function.
When a callback is omitted from a DAO method, return a Promise that
resolves to the value normally passed to the callback of that method.
If a callback is provided, behave normally.
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')
Class methods affected:
- create
- updateOrCreate / upsert
- findOrCreate
- exists
- find
- findOne
- findById
- findByIds
- remove / deleteAll / destroyAll
- removeById / deleteById / destroyById
- count
- update / updateAll
Prototype methods affected:
- save
- delete / remove / destroy
- updateAttribute
- updateAttributes
- reload
Exceptions / edge cases:
- create() used to return the data object that was passed in, even if
no callback was provided. Now, if a callback is provided, it will
return the data object, otherwise it will return a Promise.
- If create() is provided an array of data objects for creation, it
will continue to always return the array. This batch creation mode
does not support promises.
- findOrCreate() has a callback of the form: cb(err, instance, created),
with the extra parameter indicating whether the instance was created
or not. When called with its promise variant, the resolver will
receive a single array parameter: [instance, created]
* Fix the idType so that it works with both MongoDB and RDBs (Raymond Feng)
* Tidy up tests so that they will work with RDBs (Raymond Feng)
* Fix JS style issues (Raymond Feng)
* Add a new property option `defaultFn` (Miroslav Bajtoš)
* Fix the null/undefined check (Raymond Feng)
* Fix createdAt type so that it won't overflow SQL server int (Raymond Feng)
* ModelBaseClass: promise mode for notifyObserversOf (Miroslav Bajtoš)
* ModelBaseClass: support promise-based observers (Miroslav Bajtoš)
* use lodash to update the findBelongsTo which now returns an array of matches (Bryan Clark)
* Add $now as shortcut default value for date property (Pradnya Baviskar)
* Fix `deleteById(id)` and other test failures (Miroslav Bajtoš)