@loopback/repository 3.7.2 → 3.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/connectors/index.js +3 -3
- package/dist/connectors/index.js.map +1 -1
- package/dist/decorators/index.js +3 -3
- package/dist/decorators/index.js.map +1 -1
- package/dist/decorators/repository.decorator.js +4 -4
- package/dist/decorators/repository.decorator.js.map +1 -1
- package/dist/define-model-class.js +2 -2
- package/dist/define-model-class.js.map +1 -1
- package/dist/define-repository-class.js +1 -1
- package/dist/define-repository-class.js.map +1 -1
- package/dist/errors/index.js +2 -2
- package/dist/errors/index.js.map +1 -1
- package/dist/index.js +16 -16
- package/dist/index.js.map +1 -1
- package/dist/mixins/index.js +1 -1
- package/dist/mixins/index.js.map +1 -1
- package/dist/mixins/repository.mixin.d.ts +1 -1
- package/dist/mixins/repository.mixin.js +4 -4
- package/dist/mixins/repository.mixin.js.map +1 -1
- package/dist/relations/belongs-to/belongs-to.accessor.js +4 -4
- package/dist/relations/belongs-to/belongs-to.accessor.js.map +1 -1
- package/dist/relations/belongs-to/belongs-to.decorator.js +2 -2
- package/dist/relations/belongs-to/belongs-to.decorator.js.map +1 -1
- package/dist/relations/belongs-to/belongs-to.helpers.js +4 -4
- package/dist/relations/belongs-to/belongs-to.helpers.js.map +1 -1
- package/dist/relations/belongs-to/belongs-to.inclusion-resolver.js +4 -4
- package/dist/relations/belongs-to/belongs-to.inclusion-resolver.js.map +1 -1
- package/dist/relations/belongs-to/belongs-to.repository.js +1 -1
- package/dist/relations/belongs-to/belongs-to.repository.js.map +1 -1
- package/dist/relations/belongs-to/index.js +4 -4
- package/dist/relations/belongs-to/index.js.map +1 -1
- package/dist/relations/has-many/has-many-through.helpers.js +8 -8
- package/dist/relations/has-many/has-many-through.helpers.js.map +1 -1
- package/dist/relations/has-many/has-many-through.inclusion-resolver.js +9 -6
- package/dist/relations/has-many/has-many-through.inclusion-resolver.js.map +1 -1
- package/dist/relations/has-many/has-many-through.repository-factory.js +7 -7
- package/dist/relations/has-many/has-many-through.repository-factory.js.map +1 -1
- package/dist/relations/has-many/has-many-through.repository.js +12 -12
- package/dist/relations/has-many/has-many-through.repository.js.map +1 -1
- package/dist/relations/has-many/has-many.decorator.js +1 -1
- package/dist/relations/has-many/has-many.decorator.js.map +1 -1
- package/dist/relations/has-many/has-many.helpers.js +4 -4
- package/dist/relations/has-many/has-many.helpers.js.map +1 -1
- package/dist/relations/has-many/has-many.inclusion-resolver.js +5 -5
- package/dist/relations/has-many/has-many.inclusion-resolver.js.map +1 -1
- package/dist/relations/has-many/has-many.repository-factory.js +4 -4
- package/dist/relations/has-many/has-many.repository-factory.js.map +1 -1
- package/dist/relations/has-many/has-many.repository.js +4 -4
- package/dist/relations/has-many/has-many.repository.js.map +1 -1
- package/dist/relations/has-many/index.js +6 -6
- package/dist/relations/has-many/index.js.map +1 -1
- package/dist/relations/has-one/has-one.decorator.js +1 -1
- package/dist/relations/has-one/has-one.decorator.js.map +1 -1
- package/dist/relations/has-one/has-one.helpers.js +4 -4
- package/dist/relations/has-one/has-one.helpers.js.map +1 -1
- package/dist/relations/has-one/has-one.inclusion-resolver.js +3 -3
- package/dist/relations/has-one/has-one.inclusion-resolver.js.map +1 -1
- package/dist/relations/has-one/has-one.repository-factory.js +4 -4
- package/dist/relations/has-one/has-one.repository-factory.js.map +1 -1
- package/dist/relations/has-one/has-one.repository.js +4 -4
- package/dist/relations/has-one/has-one.repository.js.map +1 -1
- package/dist/relations/has-one/index.js +3 -3
- package/dist/relations/has-one/index.js.map +1 -1
- package/dist/relations/index.js +6 -6
- package/dist/relations/index.js.map +1 -1
- package/dist/relations/relation.decorator.js +1 -1
- package/dist/relations/relation.decorator.js.map +1 -1
- package/dist/relations/relation.helpers.d.ts +3 -1
- package/dist/relations/relation.helpers.js +47 -14
- package/dist/relations/relation.helpers.js.map +1 -1
- package/dist/repositories/constraint-utils.js +4 -4
- package/dist/repositories/constraint-utils.js.map +1 -1
- package/dist/repositories/index.js +5 -5
- package/dist/repositories/index.js.map +1 -1
- package/dist/repositories/kv.repository.bridge.js +7 -7
- package/dist/repositories/kv.repository.bridge.js.map +1 -1
- package/dist/repositories/legacy-juggler-bridge.js +13 -13
- package/dist/repositories/legacy-juggler-bridge.js.map +1 -1
- package/dist/types/array.js +1 -1
- package/dist/types/array.js.map +1 -1
- package/dist/types/buffer.js +1 -1
- package/dist/types/buffer.js.map +1 -1
- package/dist/types/date.js +1 -1
- package/dist/types/date.js.map +1 -1
- package/dist/types/number.js +1 -1
- package/dist/types/number.js.map +1 -1
- package/dist/types/object.js +1 -1
- package/dist/types/object.js.map +1 -1
- package/dist/types/union.js +1 -1
- package/dist/types/union.js.map +1 -1
- package/package.json +10 -10
- package/src/relations/has-many/has-many-through.inclusion-resolver.ts +4 -1
- package/src/relations/relation.helpers.ts +41 -10
|
@@ -118,7 +118,10 @@ export function createHasManyThroughInclusionResolver<
|
|
|
118
118
|
Target,
|
|
119
119
|
TargetRelations,
|
|
120
120
|
StringKeyOf<Target>
|
|
121
|
-
>(targetRepo, targetKey, targetIds as unknown as [], scope,
|
|
121
|
+
>(targetRepo, targetKey, targetIds as unknown as [], scope, {
|
|
122
|
+
...options,
|
|
123
|
+
isThroughModelInclude: true,
|
|
124
|
+
});
|
|
122
125
|
result.push(targetEntityList);
|
|
123
126
|
} else {
|
|
124
127
|
// no entities found, add undefined to results
|
|
@@ -35,29 +35,60 @@ export async function findByForeignKeys<
|
|
|
35
35
|
targetRepository: EntityCrudRepository<Target, unknown, TargetRelations>,
|
|
36
36
|
fkName: ForeignKey,
|
|
37
37
|
fkValues: Target[ForeignKey][] | Target[ForeignKey],
|
|
38
|
-
scope?: Filter<Target
|
|
38
|
+
scope?: Filter<Target> & {totalLimit?: number},
|
|
39
39
|
options?: Options,
|
|
40
40
|
): Promise<(Target & TargetRelations)[]> {
|
|
41
41
|
let value;
|
|
42
42
|
scope = cloneDeep(scope);
|
|
43
|
-
|
|
44
43
|
if (Array.isArray(fkValues)) {
|
|
45
44
|
if (fkValues.length === 0) return [];
|
|
46
45
|
value = fkValues.length === 1 ? fkValues[0] : {inq: fkValues};
|
|
47
46
|
} else {
|
|
48
47
|
value = fkValues;
|
|
49
48
|
}
|
|
49
|
+
let useScopeFilterGlobally = false;
|
|
50
|
+
if (options) {
|
|
51
|
+
useScopeFilterGlobally = options.isThroughModelInclude;
|
|
52
|
+
//if its an include from a through model, fkValues will be an array
|
|
53
|
+
//however, in this case we DO want to use the scope in the entire query
|
|
54
|
+
//no in a per fk basis
|
|
55
|
+
}
|
|
56
|
+
//This code is to keep backward compatability. See https://github.com/loopbackio/loopback-next/issues/6832
|
|
57
|
+
//for more info
|
|
58
|
+
if (scope?.totalLimit) {
|
|
59
|
+
scope.limit = scope.totalLimit;
|
|
60
|
+
useScopeFilterGlobally = true;
|
|
61
|
+
delete scope.totalLimit;
|
|
62
|
+
}
|
|
50
63
|
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
//
|
|
55
|
-
scope
|
|
64
|
+
const isScopeSet = scope && !_.isEmpty(scope);
|
|
65
|
+
if (isScopeSet && Array.isArray(fkValues) && !useScopeFilterGlobally) {
|
|
66
|
+
// since there is a scope, there could be a where filter, a limit, an order
|
|
67
|
+
// and we should run the scope in multiple queries so we can respect the
|
|
68
|
+
// scope filter params
|
|
69
|
+
const findPromises = fkValues.map(fk => {
|
|
70
|
+
const where = {[fkName]: fk} as unknown as Where<Target>;
|
|
71
|
+
let localScope = cloneDeep(scope);
|
|
72
|
+
// combine where clause to scope filter
|
|
73
|
+
localScope = new FilterBuilder(localScope).impose({where}).filter;
|
|
74
|
+
return targetRepository.find(localScope, options);
|
|
75
|
+
});
|
|
76
|
+
return Promise.all(findPromises).then(findResults => {
|
|
77
|
+
//findResults is an array of arrays for each scope result, so we need to flatten it before returning it
|
|
78
|
+
return _.flatten(findResults);
|
|
79
|
+
});
|
|
56
80
|
} else {
|
|
57
|
-
|
|
58
|
-
}
|
|
81
|
+
const where = {[fkName]: value} as unknown as Where<Target>;
|
|
59
82
|
|
|
60
|
-
|
|
83
|
+
if (isScopeSet) {
|
|
84
|
+
// combine where clause to scope filter
|
|
85
|
+
scope = new FilterBuilder(scope).impose({where}).filter;
|
|
86
|
+
} else {
|
|
87
|
+
scope = {where} as Filter<Target>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return targetRepository.find(scope, options);
|
|
91
|
+
}
|
|
61
92
|
}
|
|
62
93
|
|
|
63
94
|
export type StringKeyOf<T> = Extract<keyof T, string>;
|