1 | // Copyright IBM Corp. 2018. All Rights Reserved.
|
2 | // Node module: loopback-datasource-juggler
|
3 | // This file is licensed under the MIT License.
|
4 | // License text available at https://opensource.org/licenses/MIT
|
5 |
|
6 | import {PersistedData, PersistedModel} from '..';
|
7 | import {Callback, Options, PromiseOrVoid} from './common';
|
8 | import {Inclusion} from './query';
|
9 |
|
10 | /**
|
11 | * Inclusion mixin
|
12 | */
|
13 | export interface InclusionMixin {
|
14 | /**
|
15 | * Enables you to load relations of several objects and optimize numbers of requests.
|
16 | *
|
17 | * Examples:
|
18 | *
|
19 | * Load all users' posts with only one additional request:
|
20 | * `User.include(users, 'posts', function() {});`
|
21 | * Or
|
22 | * `User.include(users, ['posts'], function() {});`
|
23 | *
|
24 | * Load all users posts and passports with two additional requests:
|
25 | * `User.include(users, ['posts', 'passports'], function() {});`
|
26 | *
|
27 | * Load all passports owner (users), and all posts of each owner loaded:
|
28 | *```Passport.include(passports, {owner: 'posts'}, function() {});
|
29 | *``` Passport.include(passports, {owner: ['posts', 'passports']});
|
30 | *``` Passport.include(passports, {owner: [{posts: 'images'}, 'passports']});
|
31 | *
|
32 | * @param {Array} objects Array of instances
|
33 | * @param {String|Object|Array} include Which relations to load.
|
34 | * @param {Object} [options] Options for CRUD
|
35 | * @param {Function} cb Callback called when relations are loaded
|
36 | *
|
37 | */
|
38 | include<T extends PersistedModel>(
|
39 | objects: PersistedData<T>[],
|
40 | include: Inclusion,
|
41 | options?: Options,
|
42 | callback?: Callback<PersistedData<T>[]>,
|
43 | ): PromiseOrVoid<PersistedData<T>[]>;
|
44 | }
|