Provides relation eager loading via the Resource.$preload
method.
- Source:
- plugins/preload.js, line 1
Methods
-
<static> Resource.$preload(arguments) → {Resource}
-
Preloads a resource's relations
The method receives a list of relation names to preload, it also handles nested relation names. If a nested relation is added to be resolved then the parent relation is also resolved.
IMPORTANT: Only
belongsTo
andbelongsToMany
relations can be preloaded.Usage:
Bike.$search({ category: 'xc' }).$preload('user', 'parts.maker'); // this will also resolve 'parts'
Preload will attempt to use the target model's
$populate
method, if not found it will fallback to simple resolving. Take a look at the Populate plugin for a $populate implementation using special API support.It is also posible to specify some query parameters to be passed to the $populate/$resolve methods using an extended form:
Bike.$search({ category: 'xc' }).$preload( 'user', { path 'parts', params: { include: 'maker' } }, // path is the relation name and params the parameters );
Parameters:
Name Type Description arguments
array Relations to preload.
- Source:
- plugins/preload.js, line 59
Returns:
self
- Type
- Resource