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.
This is especially useful for relations/prototype scopes, as it allows
you to dynamically deduce the target model from the current receiver
(model instance). This is an advanced option that should otherwise have
no effect on the previous/default functionality. Basically, the
targetClass is taken out of the closure and handled by a method called
targetModel now.
Add the ability to set static/dynamic filtering (where, order, limit,
skip, fields …) and property mapping/transfer (de-normalization) for
hasMany/hasOne.
Store the class of the results returned by a scope find method.
This class is different from the "targetClass" when the relations
is using a third "through" model (e.g. hasAndBelongsToMany).