@mikro-orm/core 6.5.10-dev.15 → 6.5.10-dev.17

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.
@@ -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>, cond: ObjectQuery<Entity>, options: FindOptions<Entity, any, any, any> | FindOneOptions<Entity, any, any, any>): Promise<ObjectQuery<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, { ...where }, options);
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, cond, options) {
280
+ async getJoinedFilters(meta, options) {
281
+ if (!this.config.get('filtersOnRelations') || !options.populate) {
282
+ return undefined;
283
+ }
281
284
  const ret = {};
282
- if (options.populate) {
283
- for (const hint of options.populate) {
284
- const field = hint.field.split(':')[0];
285
- const prop = meta.properties[field];
286
- const strategy = (0, utils_2.getLoadingStrategy)(prop.strategy || hint.strategy || options.strategy || this.config.get('loadStrategy'), prop.kind);
287
- const joined = strategy === enums_1.LoadStrategy.JOINED && prop.kind !== enums_1.ReferenceKind.SCALAR;
288
- if (!joined && !hint.filter) {
289
- continue;
290
- }
291
- const where = await this.applyFilters(prop.type, {}, options.filters ?? {}, 'read', { ...options, populate: hint.children });
292
- const where2 = await this.getJoinedFilters(prop.targetMeta, {}, { ...options, populate: hint.children, populateWhere: enums_1.PopulateHint.ALL });
293
- if (utils_1.Utils.hasObjectKeys(where)) {
294
- ret[field] = ret[field] ? { $and: [where, ret[field]] } : where;
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
- if (utils_1.Utils.hasObjectKeys(where2)) {
297
- if (ret[field]) {
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, { ...where }, options);
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, { ...where }, options);
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/index.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * @packageDocumentation
3
3
  * @module core
4
4
  */
5
- export { Constructor, ConnectionType, Dictionary, PrimaryKeyProp, Primary, IPrimaryKey, ObjectQuery, FilterQuery, IWrappedEntity, EntityName, EntityData, Highlighter, MaybePromise, AnyEntity, EntityClass, EntityProperty, EntityMetadata, QBFilterQuery, PopulateOptions, Populate, Loaded, New, LoadedReference, LoadedCollection, IMigrator, IMigrationGenerator, MigratorEvent, GetRepository, EntityRepositoryType, MigrationObject, DeepPartial, PrimaryProperty, Cast, IsUnknown, EntityDictionary, EntityDTO, MigrationDiff, GenerateOptions, FilterObject, IEntityGenerator, ISeedManager, EntityClassGroup, OptionalProps, EagerProps, HiddenProps, RequiredEntityData, CheckCallback, IndexCallback, SimpleColumnMeta, Rel, Ref, ScalarRef, EntityRef, ISchemaGenerator, UmzugMigration, MigrateOptions, MigrationResult, MigrationRow, EntityKey, EntityValue, EntityDataValue, FilterKey, Opt, EntityType, FromEntityType, Selected, IsSubset, NoInfer, EntityProps, ExpandProperty, ExpandScalar, FilterItemValue, ExpandQuery, Scalar, ExpandHint, Hidden, FilterValue, MergeLoaded, MergeSelected, Config, DefineConfig, TypeConfig, ClearDatabaseOptions, CreateSchemaOptions, EnsureDatabaseOptions, UpdateSchemaOptions, DropSchemaOptions, RefreshDatabaseOptions, AutoPath, UnboxArray, MetadataProcessor, ImportsResolver, RequiredNullable, } from './typings';
5
+ export { Constructor, ConnectionType, Dictionary, PrimaryKeyProp, Primary, IPrimaryKey, ObjectQuery, FilterQuery, IWrappedEntity, EntityName, EntityData, Highlighter, MaybePromise, AnyEntity, EntityClass, EntityProperty, EntityMetadata, QBFilterQuery, PopulateOptions, Populate, Loaded, New, LoadedReference, LoadedCollection, IMigrator, IMigrationGenerator, MigratorEvent, GetRepository, EntityRepositoryType, MigrationObject, DeepPartial, PrimaryProperty, Cast, IsUnknown, EntityDictionary, EntityDTO, MigrationDiff, GenerateOptions, FilterObject, IEntityGenerator, ISeedManager, EntityClassGroup, OptionalProps, EagerProps, HiddenProps, RequiredEntityData, CheckCallback, IndexCallback, SimpleColumnMeta, Rel, Ref, ScalarRef, EntityRef, ISchemaGenerator, UmzugMigration, MigrateOptions, MigrationResult, MigrationRow, EntityKey, EntityValue, EntityDataValue, FilterKey, Opt, EntityType, FromEntityType, Selected, IsSubset, NoInfer, EntityProps, ExpandProperty, ExpandScalar, FilterItemValue, ExpandQuery, Scalar, ExpandHint, Hidden, FilterValue, MergeLoaded, MergeSelected, Config, DefineConfig, TypeConfig, AnyString, ClearDatabaseOptions, CreateSchemaOptions, EnsureDatabaseOptions, UpdateSchemaOptions, DropSchemaOptions, RefreshDatabaseOptions, AutoPath, UnboxArray, MetadataProcessor, ImportsResolver, RequiredNullable, } from './typings';
6
6
  export * from './enums';
7
7
  export * from './errors';
8
8
  export * from './exceptions';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "6.5.10-dev.15",
3
+ "version": "6.5.10-dev.17",
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.15",
67
+ "mikro-orm": "6.5.10-dev.17",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }
@@ -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: {
@@ -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
  });
@@ -89,7 +89,7 @@ export declare const ALIAS_REPLACEMENT_RE = "\\[::alias::\\]";
89
89
  * export class Author { ... }
90
90
  * ```
91
91
  */
92
- export declare function raw<T extends object = any, R = any>(sql: EntityKey<T> | EntityKey<T>[] | AnyString | ((alias: string) => string) | RawQueryFragment, params?: readonly unknown[] | Dictionary<unknown>): R;
92
+ export declare function raw<T extends object = any, R = any>(sql: EntityKey<T> | EntityKey<T>[] | AnyString | ((alias: string) => string) | RawQueryFragment, params?: readonly unknown[] | Dictionary<unknown>): NoInfer<R>;
93
93
  /**
94
94
  * Alternative to the `raw()` helper allowing to use it as a tagged template function for the simple cases.
95
95
  *
@@ -106,7 +106,7 @@ export declare function raw<T extends object = any, R = any>(sql: EntityKey<T> |
106
106
  */
107
107
  export declare function sql(sql: readonly string[], ...values: unknown[]): any;
108
108
  export declare namespace sql {
109
- var ref: <T extends object>(...keys: string[]) => RawQueryFragment;
109
+ var ref: <T extends object>(...keys: string[]) => NoInfer<RawQueryFragment>;
110
110
  var now: (length?: number) => string;
111
111
  var lower: <T extends object>(key: string | ((alias: string) => string)) => string;
112
112
  var upper: <T extends object>(key: string | ((alias: string) => string)) => string;