@mikro-orm/core 6.5.10-dev.16 → 6.5.10-dev.18
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/EntityManager.d.ts +1 -1
- package/EntityManager.js +32 -24
- package/package.json +2 -2
- package/utils/Configuration.d.ts +2 -0
- package/utils/Configuration.js +4 -0
package/EntityManager.d.ts
CHANGED
|
@@ -119,7 +119,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
119
119
|
protected processWhere<Entity extends object, Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(entityName: string, where: FilterQuery<Entity>, options: FindOptions<Entity, Hint, Fields, Excludes> | FindOneOptions<Entity, Hint, Fields, Excludes>, type: 'read' | 'update' | 'delete'): Promise<FilterQuery<Entity>>;
|
|
120
120
|
protected applyDiscriminatorCondition<Entity extends object>(entityName: string, where: FilterQuery<Entity>): FilterQuery<Entity>;
|
|
121
121
|
protected createPopulateWhere<Entity extends object>(cond: ObjectQuery<Entity>, options: FindOptions<Entity, any, any, any> | FindOneOptions<Entity, any, any, any> | CountOptions<Entity, any>): ObjectQuery<Entity>;
|
|
122
|
-
protected getJoinedFilters<Entity extends object>(meta: EntityMetadata<Entity>,
|
|
122
|
+
protected getJoinedFilters<Entity extends object>(meta: EntityMetadata<Entity>, options: FindOptions<Entity, any, any, any> | FindOneOptions<Entity, any, any, any>): Promise<ObjectQuery<Entity> | undefined>;
|
|
123
123
|
/**
|
|
124
124
|
* When filters are active on M:1 or 1:1 relations, we need to ref join them eagerly as they might affect the FK value.
|
|
125
125
|
*/
|
package/EntityManager.js
CHANGED
|
@@ -143,7 +143,7 @@ class EntityManager {
|
|
|
143
143
|
// save the original hint value so we know it was infer/all
|
|
144
144
|
options._populateWhere = options.populateWhere ?? this.config.get('populateWhere');
|
|
145
145
|
options.populateWhere = this.createPopulateWhere({ ...where }, options);
|
|
146
|
-
options.populateFilter = await this.getJoinedFilters(meta,
|
|
146
|
+
options.populateFilter = await this.getJoinedFilters(meta, options);
|
|
147
147
|
const results = await em.driver.find(entityName, where, { ctx: em.transactionContext, em, ...options });
|
|
148
148
|
if (results.length === 0) {
|
|
149
149
|
await em.storeCache(options.cache, cached, []);
|
|
@@ -277,29 +277,37 @@ class EntityManager {
|
|
|
277
277
|
}
|
|
278
278
|
return ret;
|
|
279
279
|
}
|
|
280
|
-
async getJoinedFilters(meta,
|
|
280
|
+
async getJoinedFilters(meta, options) {
|
|
281
|
+
if (!this.config.get('filtersOnRelations') || !options.populate) {
|
|
282
|
+
return undefined;
|
|
283
|
+
}
|
|
281
284
|
const ret = {};
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
285
|
+
for (const hint of options.populate) {
|
|
286
|
+
const field = hint.field.split(':')[0];
|
|
287
|
+
const prop = meta.properties[field];
|
|
288
|
+
const strategy = (0, utils_2.getLoadingStrategy)(prop.strategy || hint.strategy || options.strategy || this.config.get('loadStrategy'), prop.kind);
|
|
289
|
+
const joined = strategy === enums_1.LoadStrategy.JOINED && prop.kind !== enums_1.ReferenceKind.SCALAR;
|
|
290
|
+
if (!joined && !hint.filter) {
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
const where = await this.applyFilters(prop.type, {}, options.filters ?? {}, 'read', {
|
|
294
|
+
...options,
|
|
295
|
+
populate: hint.children,
|
|
296
|
+
});
|
|
297
|
+
const where2 = await this.getJoinedFilters(prop.targetMeta, {
|
|
298
|
+
...options,
|
|
299
|
+
populate: hint.children,
|
|
300
|
+
populateWhere: enums_1.PopulateHint.ALL,
|
|
301
|
+
});
|
|
302
|
+
if (utils_1.Utils.hasObjectKeys(where)) {
|
|
303
|
+
ret[field] = ret[field] ? { $and: [where, ret[field]] } : where;
|
|
304
|
+
}
|
|
305
|
+
if (where2 && utils_1.Utils.hasObjectKeys(where2)) {
|
|
306
|
+
if (ret[field]) {
|
|
307
|
+
utils_1.Utils.merge(ret[field], where2);
|
|
295
308
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
utils_1.Utils.merge(ret[field], where2);
|
|
299
|
-
}
|
|
300
|
-
else {
|
|
301
|
-
ret[field] = where2;
|
|
302
|
-
}
|
|
309
|
+
else {
|
|
310
|
+
ret[field] = where2;
|
|
303
311
|
}
|
|
304
312
|
}
|
|
305
313
|
}
|
|
@@ -580,7 +588,7 @@ class EntityManager {
|
|
|
580
588
|
// save the original hint value so we know it was infer/all
|
|
581
589
|
options._populateWhere = options.populateWhere ?? this.config.get('populateWhere');
|
|
582
590
|
options.populateWhere = this.createPopulateWhere({ ...where }, options);
|
|
583
|
-
options.populateFilter = await this.getJoinedFilters(meta,
|
|
591
|
+
options.populateFilter = await this.getJoinedFilters(meta, options);
|
|
584
592
|
const data = await em.driver.findOne(entityName, where, {
|
|
585
593
|
ctx: em.transactionContext,
|
|
586
594
|
em,
|
|
@@ -1265,7 +1273,7 @@ class EntityManager {
|
|
|
1265
1273
|
const meta = em.metadata.find(entityName);
|
|
1266
1274
|
options._populateWhere = options.populateWhere ?? this.config.get('populateWhere');
|
|
1267
1275
|
options.populateWhere = this.createPopulateWhere({ ...where }, options);
|
|
1268
|
-
options.populateFilter = await this.getJoinedFilters(meta,
|
|
1276
|
+
options.populateFilter = await this.getJoinedFilters(meta, options);
|
|
1269
1277
|
em.validator.validateParams(where);
|
|
1270
1278
|
delete options.orderBy;
|
|
1271
1279
|
const cacheKey = em.cacheKey(entityName, options, 'em.count', where);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "6.5.10-dev.
|
|
3
|
+
"version": "6.5.10-dev.18",
|
|
4
4
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"esprima": "4.0.1",
|
|
65
65
|
"fs-extra": "11.3.2",
|
|
66
66
|
"globby": "11.1.0",
|
|
67
|
-
"mikro-orm": "6.5.10-dev.
|
|
67
|
+
"mikro-orm": "6.5.10-dev.18",
|
|
68
68
|
"reflect-metadata": "0.2.2"
|
|
69
69
|
}
|
|
70
70
|
}
|
package/utils/Configuration.d.ts
CHANGED
|
@@ -61,6 +61,7 @@ export declare class Configuration<D extends IDatabaseDriver = IDatabaseDriver,
|
|
|
61
61
|
onQuery: (sql: string) => string;
|
|
62
62
|
autoJoinOneToOneOwner: true;
|
|
63
63
|
autoJoinRefsForFilters: true;
|
|
64
|
+
filtersOnRelations: true;
|
|
64
65
|
propagationOnPrototype: true;
|
|
65
66
|
populateAfterFlush: true;
|
|
66
67
|
serialization: {
|
|
@@ -337,6 +338,7 @@ export interface MikroORMOptions<D extends IDatabaseDriver = IDatabaseDriver, EM
|
|
|
337
338
|
onQuery: (sql: string, params: unknown[]) => string;
|
|
338
339
|
autoJoinOneToOneOwner: boolean;
|
|
339
340
|
autoJoinRefsForFilters: boolean;
|
|
341
|
+
filtersOnRelations: boolean;
|
|
340
342
|
propagationOnPrototype: boolean;
|
|
341
343
|
populateAfterFlush: boolean;
|
|
342
344
|
serialization: {
|
package/utils/Configuration.js
CHANGED
|
@@ -55,6 +55,7 @@ class Configuration {
|
|
|
55
55
|
onQuery: sql => sql,
|
|
56
56
|
autoJoinOneToOneOwner: true,
|
|
57
57
|
autoJoinRefsForFilters: true,
|
|
58
|
+
filtersOnRelations: true,
|
|
58
59
|
propagationOnPrototype: true,
|
|
59
60
|
populateAfterFlush: true,
|
|
60
61
|
serialization: {
|
|
@@ -339,6 +340,9 @@ class Configuration {
|
|
|
339
340
|
Object.keys(this.options.filters).forEach(key => {
|
|
340
341
|
this.options.filters[key].default ??= true;
|
|
341
342
|
});
|
|
343
|
+
if (!this.options.filtersOnRelations) {
|
|
344
|
+
this.options.autoJoinRefsForFilters ??= false;
|
|
345
|
+
}
|
|
342
346
|
this.options.subscribers = Utils_1.Utils.unique(this.options.subscribers).map(subscriber => {
|
|
343
347
|
return subscriber.constructor.name === 'Function' ? new subscriber() : subscriber;
|
|
344
348
|
});
|