@mikro-orm/core 7.0.0-dev.114 → 7.0.0-dev.116

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.
Files changed (55) hide show
  1. package/EntityManager.d.ts +8 -8
  2. package/EntityManager.js +42 -62
  3. package/MikroORM.d.ts +1 -1
  4. package/MikroORM.js +2 -3
  5. package/drivers/DatabaseDriver.d.ts +11 -11
  6. package/drivers/DatabaseDriver.js +7 -8
  7. package/drivers/IDatabaseDriver.d.ts +10 -10
  8. package/entity/Collection.js +5 -5
  9. package/entity/EntityAssigner.js +9 -9
  10. package/entity/EntityFactory.js +14 -17
  11. package/entity/EntityHelper.d.ts +2 -2
  12. package/entity/EntityHelper.js +2 -2
  13. package/entity/EntityLoader.d.ts +3 -3
  14. package/entity/EntityLoader.js +17 -16
  15. package/entity/WrappedEntity.js +1 -1
  16. package/entity/defineEntity.d.ts +11 -11
  17. package/errors.d.ts +8 -8
  18. package/errors.js +14 -13
  19. package/hydration/ObjectHydrator.js +23 -16
  20. package/metadata/EntitySchema.d.ts +5 -5
  21. package/metadata/EntitySchema.js +23 -21
  22. package/metadata/MetadataDiscovery.d.ts +2 -3
  23. package/metadata/MetadataDiscovery.js +117 -90
  24. package/metadata/MetadataProvider.js +2 -0
  25. package/metadata/MetadataStorage.d.ts +13 -6
  26. package/metadata/MetadataStorage.js +64 -19
  27. package/metadata/MetadataValidator.d.ts +2 -2
  28. package/metadata/MetadataValidator.js +22 -28
  29. package/metadata/types.d.ts +3 -3
  30. package/package.json +1 -1
  31. package/serialization/EntitySerializer.d.ts +3 -0
  32. package/serialization/EntitySerializer.js +15 -13
  33. package/serialization/EntityTransformer.js +6 -6
  34. package/serialization/SerializationContext.d.ts +6 -6
  35. package/typings.d.ts +16 -14
  36. package/typings.js +15 -10
  37. package/unit-of-work/ChangeSet.d.ts +2 -3
  38. package/unit-of-work/ChangeSet.js +2 -3
  39. package/unit-of-work/ChangeSetComputer.js +3 -3
  40. package/unit-of-work/ChangeSetPersister.js +14 -14
  41. package/unit-of-work/CommitOrderCalculator.d.ts +12 -10
  42. package/unit-of-work/CommitOrderCalculator.js +13 -13
  43. package/unit-of-work/UnitOfWork.d.ts +3 -3
  44. package/unit-of-work/UnitOfWork.js +46 -45
  45. package/utils/AbstractSchemaGenerator.js +7 -7
  46. package/utils/Configuration.d.ts +0 -5
  47. package/utils/DataloaderUtils.js +13 -11
  48. package/utils/EntityComparator.d.ts +6 -6
  49. package/utils/EntityComparator.js +26 -24
  50. package/utils/QueryHelper.d.ts +5 -5
  51. package/utils/QueryHelper.js +7 -7
  52. package/utils/TransactionManager.js +1 -1
  53. package/utils/Utils.d.ts +1 -1
  54. package/utils/Utils.js +1 -2
  55. package/utils/env-vars.js +0 -1
@@ -11,7 +11,7 @@ export class DataloaderUtils {
11
11
  static groupPrimaryKeysByEntityAndOpts(refsWithOpts) {
12
12
  const map = new Map();
13
13
  for (const [ref, opts] of refsWithOpts) {
14
- /* The key is a combination of the className and a stringified version if the load options because we want
14
+ /* The key is a combination of the uniqueName (a unique table name based identifier) and a stringified version if the load options because we want
15
15
  to map each combination of entities/options into separate find queries in order to return accurate results.
16
16
  This could be further optimized finding the "lowest common denominator" among the different options
17
17
  for each Entity and firing a single query for each Entity instead of Entity+options combination.
@@ -24,7 +24,7 @@ export class DataloaderUtils {
24
24
  Thus such approach should probably be configurable, if not opt-in.
25
25
  NOTE: meta + opts multi maps (https://github.com/martian17/ds-js) might be a more elegant way
26
26
  to implement this but not necessarily faster. */
27
- const key = `${helper(ref).__meta.className}|${JSON.stringify(opts ?? {})}`;
27
+ const key = `${helper(ref).__meta.uniqueName}|${JSON.stringify(opts ?? {})}`;
28
28
  let primaryKeysSet = map.get(key);
29
29
  if (primaryKeysSet == null) {
30
30
  primaryKeysSet = new Set();
@@ -42,9 +42,10 @@ export class DataloaderUtils {
42
42
  return async (refsWithOpts) => {
43
43
  const groupedIdsMap = DataloaderUtils.groupPrimaryKeysByEntityAndOpts(refsWithOpts);
44
44
  const promises = Array.from(groupedIdsMap).map(([key, idsSet]) => {
45
- const className = key.substring(0, key.indexOf('|'));
45
+ const uniqueName = key.substring(0, key.indexOf('|'));
46
46
  const opts = JSON.parse(key.substring(key.indexOf('|') + 1));
47
- return em.find(className, Array.from(idsSet), opts);
47
+ const meta = em.getMetadata().getByUniqueName(uniqueName);
48
+ return em.find(meta.class, Array.from(idsSet), opts);
48
49
  });
49
50
  await Promise.all(promises);
50
51
  /* Instead of assigning each find result to the original reference we use a shortcut
@@ -70,7 +71,7 @@ export class DataloaderUtils {
70
71
  The value is another Map which we can use to filter the find query to get results pertaining to the collections that have been dataloaded:
71
72
  its keys are the props we are going to filter to and its values are the corresponding PKs.
72
73
  */
73
- const key = `${col.property.targetMeta.className}|${JSON.stringify(opts ?? {})}`;
74
+ const key = `${col.property.targetMeta.uniqueName}|${JSON.stringify(opts ?? {})}`;
74
75
  let filterMap = entitiesMap.get(key); // We are going to use this map to filter the entities pertaining to the collections that have been dataloaded.
75
76
  if (filterMap == null) {
76
77
  filterMap = new Map();
@@ -97,9 +98,10 @@ export class DataloaderUtils {
97
98
  */
98
99
  static entitiesAndOptsMapToQueries(entitiesAndOptsMap, em) {
99
100
  return Array.from(entitiesAndOptsMap, async ([key, filterMap]) => {
100
- const className = key.substring(0, key.indexOf('|'));
101
+ const uniqueName = key.substring(0, key.indexOf('|'));
101
102
  const opts = JSON.parse(key.substring(key.indexOf('|') + 1));
102
- const res = await em.find(className, opts?.where != null && Object.keys(opts.where).length > 0 ?
103
+ const meta = em.getMetadata().getByUniqueName(uniqueName);
104
+ const res = await em.find(meta.class, opts?.where != null && Object.keys(opts.where).length > 0 ?
103
105
  {
104
106
  $and: [
105
107
  {
@@ -121,7 +123,7 @@ export class DataloaderUtils {
121
123
  ...(opts.populate === false ? [] : opts.populate ?? []),
122
124
  ...Array.from(filterMap.keys()).filter(
123
125
  // We need to do so only if the inverse side is a collection, because we can already retrieve the PK from a reference without having to load it
124
- prop => em.getMetadata(className).properties[prop]?.ref !== true),
126
+ prop => meta.properties[prop]?.ref !== true),
125
127
  ],
126
128
  });
127
129
  return [key, res];
@@ -164,7 +166,7 @@ export class DataloaderUtils {
164
166
  // We need to filter the results in order to map each input collection
165
167
  // to a subset of each query matching the collection items.
166
168
  return collsWithOpts.map(([col, opts]) => {
167
- const key = `${col.property.targetMeta.className}|${JSON.stringify(opts ?? {})}`;
169
+ const key = `${col.property.targetMeta.uniqueName}|${JSON.stringify(opts ?? {})}`;
168
170
  const entities = resultsMap.get(key);
169
171
  if (entities == null) {
170
172
  // Should never happen
@@ -183,7 +185,7 @@ export class DataloaderUtils {
183
185
  return async (collsWithOpts) => {
184
186
  const groups = new Map();
185
187
  for (const [col, opts] of collsWithOpts) {
186
- const key = `${col.property.targetMeta.className}.${col.property.name}|${JSON.stringify(opts ?? {})}`;
188
+ const key = `${col.property.targetMeta.uniqueName}.${col.property.name}|${JSON.stringify(opts ?? {})}`;
187
189
  const value = groups.get(key) ?? [];
188
190
  value.push([col, opts ?? {}]);
189
191
  groups.set(key, value);
@@ -198,7 +200,7 @@ export class DataloaderUtils {
198
200
  const owners = group.map(c => c[0].owner);
199
201
  const $or = [];
200
202
  // a bit of a hack, but we need to prefix the key, since we have only a column name, not a property name
201
- const alias = em.config.getNamingStrategy().aliasName(prop.pivotEntity, 0);
203
+ const alias = em.config.getNamingStrategy().aliasName(Utils.className(prop.pivotEntity), 0);
202
204
  const fk = `${alias}.${Utils.getPrimaryKeyHash(prop.joinColumns)}`;
203
205
  for (const c of group) {
204
206
  $or.push({ $and: [c[1]?.where ?? {}, { [fk]: c[0].owner }] });
@@ -20,19 +20,19 @@ export declare class EntityComparator {
20
20
  /**
21
21
  * Computes difference between two entities.
22
22
  */
23
- diffEntities<T>(entityName: string, a: EntityData<T>, b: EntityData<T>, options?: {
23
+ diffEntities<T extends object>(entityName: EntityName<T>, a: EntityData<T>, b: EntityData<T>, options?: {
24
24
  includeInverseSides?: boolean;
25
25
  }): EntityData<T>;
26
- matching<T>(entityName: string, a: EntityData<T>, b: EntityData<T>): boolean;
26
+ matching<T extends object>(entityName: EntityName<T>, a: EntityData<T>, b: EntityData<T>): boolean;
27
27
  /**
28
28
  * Removes ORM specific code from entities and prepares it for serializing. Used before change set computation.
29
29
  * References will be mapped to primary keys, collections to arrays of primary keys.
30
30
  */
31
- prepareEntity<T>(entity: T): EntityData<T>;
31
+ prepareEntity<T extends object>(entity: T): EntityData<T>;
32
32
  /**
33
33
  * Maps database columns to properties.
34
34
  */
35
- mapResult<T>(entityName: string, result: EntityDictionary<T>): EntityData<T>;
35
+ mapResult<T>(meta: EntityMetadata<T>, result: EntityDictionary<T>): EntityData<T>;
36
36
  /**
37
37
  * @internal Highly performance-sensitive method.
38
38
  */
@@ -64,7 +64,7 @@ export declare class EntityComparator {
64
64
  /**
65
65
  * @internal Highly performance-sensitive method.
66
66
  */
67
- getResultMapper<T>(entityName: string): ResultMapper<T>;
67
+ getResultMapper<T>(meta: EntityMetadata<T>): ResultMapper<T>;
68
68
  private getPropertyCondition;
69
69
  private getEmbeddedArrayPropertySnapshot;
70
70
  /**
@@ -78,7 +78,7 @@ export declare class EntityComparator {
78
78
  /**
79
79
  * @internal Highly performance-sensitive method.
80
80
  */
81
- getEntityComparator<T extends object>(entityName: string): Comparator<T>;
81
+ getEntityComparator<T extends object>(entityName: EntityName<T>): Comparator<T>;
82
82
  private getGenericComparator;
83
83
  private getPropertyComparator;
84
84
  private wrap;
@@ -3,6 +3,7 @@ import { ReferenceKind } from '../enums.js';
3
3
  import { compareArrays, compareBooleans, compareBuffers, compareObjects, equals, parseJsonSafe, Utils } from './Utils.js';
4
4
  import { JsonType } from '../types/JsonType.js';
5
5
  import { Raw } from './RawQueryFragment.js';
6
+ import { EntityIdentifier } from '../entity/EntityIdentifier.js';
6
7
  export class EntityComparator {
7
8
  metadata;
8
9
  platform;
@@ -33,21 +34,21 @@ export class EntityComparator {
33
34
  * References will be mapped to primary keys, collections to arrays of primary keys.
34
35
  */
35
36
  prepareEntity(entity) {
36
- const generator = this.getSnapshotGenerator(entity.constructor.name);
37
+ const generator = this.getSnapshotGenerator(entity.constructor);
37
38
  return Utils.callCompiledFunction(generator, entity);
38
39
  }
39
40
  /**
40
41
  * Maps database columns to properties.
41
42
  */
42
- mapResult(entityName, result) {
43
- const mapper = this.getResultMapper(entityName);
43
+ mapResult(meta, result) {
44
+ const mapper = this.getResultMapper(meta);
44
45
  return Utils.callCompiledFunction(mapper, result);
45
46
  }
46
47
  /**
47
48
  * @internal Highly performance-sensitive method.
48
49
  */
49
50
  getPkGetter(meta) {
50
- const exists = this.pkGetters.get(meta.className);
51
+ const exists = this.pkGetters.get(meta);
51
52
  /* v8 ignore next */
52
53
  if (exists) {
53
54
  return exists;
@@ -90,14 +91,14 @@ export class EntityComparator {
90
91
  const code = `// compiled pk serializer for entity ${meta.className}\n`
91
92
  + `return function(entity) {\n${lines.join('\n')}\n}`;
92
93
  const pkSerializer = Utils.createFunction(context, code);
93
- this.pkGetters.set(meta.className, pkSerializer);
94
+ this.pkGetters.set(meta, pkSerializer);
94
95
  return pkSerializer;
95
96
  }
96
97
  /**
97
98
  * @internal Highly performance-sensitive method.
98
99
  */
99
100
  getPkGetterConverted(meta) {
100
- const exists = this.pkGettersConverted.get(meta.className);
101
+ const exists = this.pkGettersConverted.get(meta);
101
102
  /* v8 ignore next */
102
103
  if (exists) {
103
104
  return exists;
@@ -140,14 +141,14 @@ export class EntityComparator {
140
141
  const code = `// compiled pk getter (with converted custom types) for entity ${meta.className}\n`
141
142
  + `return function(entity) {\n${lines.join('\n')}\n}`;
142
143
  const pkSerializer = Utils.createFunction(context, code);
143
- this.pkGettersConverted.set(meta.className, pkSerializer);
144
+ this.pkGettersConverted.set(meta, pkSerializer);
144
145
  return pkSerializer;
145
146
  }
146
147
  /**
147
148
  * @internal Highly performance-sensitive method.
148
149
  */
149
150
  getPkSerializer(meta) {
150
- const exists = this.pkSerializers.get(meta.className);
151
+ const exists = this.pkSerializers.get(meta);
151
152
  /* v8 ignore next */
152
153
  if (exists) {
153
154
  return exists;
@@ -192,19 +193,18 @@ export class EntityComparator {
192
193
  const code = `// compiled pk serializer for entity ${meta.className}\n`
193
194
  + `return function(entity) {\n${lines.join('\n')}\n}`;
194
195
  const pkSerializer = Utils.createFunction(context, code);
195
- this.pkSerializers.set(meta.className, pkSerializer);
196
+ this.pkSerializers.set(meta, pkSerializer);
196
197
  return pkSerializer;
197
198
  }
198
199
  /**
199
200
  * @internal Highly performance-sensitive method.
200
201
  */
201
202
  getSnapshotGenerator(entityName) {
202
- entityName = Utils.className(entityName);
203
- const exists = this.snapshotGenerators.get(entityName);
203
+ const meta = this.metadata.find(entityName);
204
+ const exists = this.snapshotGenerators.get(meta);
204
205
  if (exists) {
205
206
  return exists;
206
207
  }
207
- const meta = this.metadata.find(entityName);
208
208
  const lines = [];
209
209
  const context = new Map();
210
210
  context.set('clone', clone);
@@ -222,7 +222,7 @@ export class EntityComparator {
222
222
  .forEach(prop => lines.push(this.getPropertySnapshot(meta, prop, context, this.wrap(prop.name), this.wrap(prop.name), [prop.name])));
223
223
  const code = `return function(entity) {\n const ret = {};\n${lines.join('\n')}\n return ret;\n}`;
224
224
  const snapshotGenerator = Utils.createFunction(context, code);
225
- this.snapshotGenerators.set(entityName, snapshotGenerator);
225
+ this.snapshotGenerators.set(meta, snapshotGenerator);
226
226
  return snapshotGenerator;
227
227
  }
228
228
  /**
@@ -272,12 +272,11 @@ export class EntityComparator {
272
272
  /**
273
273
  * @internal Highly performance-sensitive method.
274
274
  */
275
- getResultMapper(entityName) {
276
- const exists = this.mappers.get(entityName);
275
+ getResultMapper(meta) {
276
+ const exists = this.mappers.get(meta);
277
277
  if (exists) {
278
278
  return exists;
279
279
  }
280
- const meta = this.metadata.get(entityName);
281
280
  const lines = [];
282
281
  const context = new Map();
283
282
  const tz = this.platform.getTimezone();
@@ -336,9 +335,9 @@ export class EntityComparator {
336
335
  context.set(`mapEmbeddedResult_${idx}`, (data) => {
337
336
  const item = parseJsonSafe(data);
338
337
  if (Array.isArray(item)) {
339
- return item.map(row => row == null ? row : this.getResultMapper(prop.type)(row));
338
+ return item.map(row => row == null ? row : this.getResultMapper(prop.targetMeta)(row));
340
339
  }
341
- return item == null ? item : this.getResultMapper(prop.type)(item);
340
+ return item == null ? item : this.getResultMapper(prop.targetMeta)(item);
342
341
  });
343
342
  lines.push(`${padding} if (typeof ${this.propName(prop.fieldNames[0])} !== 'undefined') {`);
344
343
  lines.push(`${padding} ret${this.wrap(prop.name)} = ${this.propName(prop.fieldNames[0])} == null ? ${this.propName(prop.fieldNames[0])} : mapEmbeddedResult_${idx}(${this.propName(prop.fieldNames[0])});`);
@@ -371,7 +370,7 @@ export class EntityComparator {
371
370
  const code = `// compiled mapper for entity ${meta.className}\n`
372
371
  + `return function(result) {\n const ret = {};\n${lines.join('\n')}\n return ret;\n}`;
373
372
  const resultMapper = Utils.createFunction(context, code);
374
- this.mappers.set(entityName, resultMapper);
373
+ this.mappers.set(meta, resultMapper);
375
374
  return resultMapper;
376
375
  }
377
376
  getPropertyCondition(path) {
@@ -519,8 +518,11 @@ export class EntityComparator {
519
518
  return val;
520
519
  };
521
520
  context.set('toArray', toArray);
521
+ context.set('EntityIdentifier', EntityIdentifier);
522
522
  ret += ` if (entity${entityKey} === null) {\n`;
523
523
  ret += ` ret${dataKey} = null;\n`;
524
+ ret += ` } else if (entity${entityKey}?.__helper.__identifier && !entity${entityKey}.__helper.hasPrimaryKey()) {\n`;
525
+ ret += ` ret${dataKey} = entity${entityKey}?.__helper.__identifier;\n`;
524
526
  ret += ` } else if (typeof entity${entityKey} !== 'undefined') {\n`;
525
527
  ret += ` ret${dataKey} = toArray(entity${entityKey}.__helper.getPrimaryKey(true));\n`;
526
528
  ret += ` }\n`;
@@ -544,11 +546,11 @@ export class EntityComparator {
544
546
  * @internal Highly performance-sensitive method.
545
547
  */
546
548
  getEntityComparator(entityName) {
547
- const exists = this.comparators.get(entityName);
549
+ const meta = this.metadata.find(entityName);
550
+ const exists = this.comparators.get(meta);
548
551
  if (exists) {
549
552
  return exists;
550
553
  }
551
- const meta = this.metadata.find(entityName);
552
554
  const lines = [];
553
555
  const context = new Map();
554
556
  context.set('compareArrays', compareArrays);
@@ -570,7 +572,7 @@ export class EntityComparator {
570
572
  const code = `// compiled comparator for entity ${meta.className}\n`
571
573
  + `return function(last, current, options) {\n const diff = {};\n${lines.join('\n')}\n return diff;\n}`;
572
574
  const comparator = Utils.createFunction(context, code);
573
- this.comparators.set(entityName, comparator);
575
+ this.comparators.set(meta, comparator);
574
576
  return comparator;
575
577
  }
576
578
  getGenericComparator(prop, cond) {
@@ -586,12 +588,12 @@ export class EntityComparator {
586
588
  getPropertyComparator(prop, context) {
587
589
  let type = prop.type.toLowerCase();
588
590
  if (prop.kind !== ReferenceKind.SCALAR && prop.kind !== ReferenceKind.EMBEDDED) {
589
- const meta2 = this.metadata.find(prop.type);
591
+ const meta2 = prop.targetMeta;
590
592
  if (meta2.primaryKeys.length > 1) {
591
593
  type = 'array';
592
594
  }
593
595
  else {
594
- type = meta2.properties[meta2.primaryKeys[0]].type.toLowerCase();
596
+ type = meta2.getPrimaryProp().type.toLowerCase();
595
597
  }
596
598
  }
597
599
  if (prop.customType) {
@@ -1,4 +1,4 @@
1
- import type { Dictionary, EntityMetadata, EntityProperty, FilterDef, FilterQuery } from '../typings.js';
1
+ import type { Dictionary, EntityMetadata, EntityName, EntityProperty, FilterDef, FilterQuery } from '../typings.js';
2
2
  import type { Platform } from '../platforms/Platform.js';
3
3
  import type { MetadataStorage } from '../metadata/MetadataStorage.js';
4
4
  import type { FilterOptions } from '../drivers/IDatabaseDriver.js';
@@ -14,9 +14,9 @@ export declare class QueryHelper {
14
14
  static liftGroupOperators<T extends object>(where: Dictionary, meta: EntityMetadata<T>, metadata: MetadataStorage, key?: string): string | undefined;
15
15
  static inlinePrimaryKeyObjects<T extends object>(where: Dictionary, meta: EntityMetadata<T>, metadata: MetadataStorage, key?: string): boolean;
16
16
  static processWhere<T extends object>(options: ProcessWhereOptions<T>): FilterQuery<T>;
17
- static getActiveFilters(entityName: string, options: FilterOptions | undefined, filters: Dictionary<FilterDef>): FilterDef[];
17
+ static getActiveFilters<T>(meta: EntityMetadata<T>, options: FilterOptions | undefined, filters: Dictionary<FilterDef>): FilterDef[];
18
18
  static mergePropertyFilters(propFilters: FilterOptions | undefined, options: FilterOptions | undefined): FilterOptions | undefined;
19
- static isFilterActive(entityName: string, filterName: string, filter: FilterDef, options: Dictionary<boolean | Dictionary>): boolean;
19
+ static isFilterActive<T>(meta: EntityMetadata<T>, filterName: string, filter: FilterDef, options: Dictionary<boolean | Dictionary>): boolean;
20
20
  static processCustomType<T extends object>(prop: EntityProperty<T>, cond: FilterQuery<T>, platform: Platform, key?: string, fromQuery?: boolean): FilterQuery<T>;
21
21
  private static isSupportedOperator;
22
22
  private static processJsonCondition;
@@ -25,11 +25,11 @@ export declare class QueryHelper {
25
25
  }
26
26
  interface ProcessWhereOptions<T> {
27
27
  where: FilterQuery<T>;
28
- entityName: string;
28
+ entityName: EntityName<T>;
29
29
  metadata: MetadataStorage;
30
30
  platform: Platform;
31
31
  aliased?: boolean;
32
- aliasMap?: Dictionary<string>;
32
+ aliasMap?: Dictionary<EntityName>;
33
33
  convertCustomTypes?: boolean;
34
34
  root?: boolean;
35
35
  type?: 'where' | 'orderBy';
@@ -98,7 +98,7 @@ export class QueryHelper {
98
98
  }));
99
99
  }
100
100
  Object.keys(where).forEach(k => {
101
- const meta2 = metadata.find(meta.properties[k]?.type) || meta;
101
+ const meta2 = metadata.find(meta.properties[k]?.targetMeta?.class) || meta;
102
102
  if (this.inlinePrimaryKeyObjects(where[k], meta2, metadata, k)) {
103
103
  where[k] = Utils.getPrimaryKeyValues(where[k], meta2, true);
104
104
  }
@@ -126,7 +126,7 @@ export class QueryHelper {
126
126
  where = { [Utils.getPrimaryKeyHash(meta.primaryKeys)]: where };
127
127
  }
128
128
  if (Array.isArray(where) && root) {
129
- const rootPrimaryKey = meta ? Utils.getPrimaryKeyHash(meta.primaryKeys) : entityName;
129
+ const rootPrimaryKey = meta ? Utils.getPrimaryKeyHash(meta.primaryKeys) : Utils.className(entityName);
130
130
  let cond = { [rootPrimaryKey]: { $in: where } };
131
131
  // @ts-ignore
132
132
  // detect tuple comparison, use `$or` in case the number of constituents don't match
@@ -175,7 +175,7 @@ export class QueryHelper {
175
175
  o[key] = QueryHelper.processWhere({
176
176
  ...options,
177
177
  where: value,
178
- entityName: prop?.type ?? entityName,
178
+ entityName: prop?.targetMeta?.class ?? entityName,
179
179
  root: false,
180
180
  });
181
181
  }
@@ -185,7 +185,7 @@ export class QueryHelper {
185
185
  return o;
186
186
  }, {});
187
187
  }
188
- static getActiveFilters(entityName, options, filters) {
188
+ static getActiveFilters(meta, options, filters) {
189
189
  if (options === false) {
190
190
  return [];
191
191
  }
@@ -197,7 +197,7 @@ export class QueryHelper {
197
197
  Object.keys(options).forEach(filter => opts[filter] = options[filter]);
198
198
  }
199
199
  return Object.keys(filters)
200
- .filter(f => QueryHelper.isFilterActive(entityName, f, filters[f], opts))
200
+ .filter(f => QueryHelper.isFilterActive(meta, f, filters[f], opts))
201
201
  .map(f => {
202
202
  filters[f].name = f;
203
203
  return filters[f];
@@ -221,8 +221,8 @@ export class QueryHelper {
221
221
  }
222
222
  return Utils.mergeConfig({}, propFilters, options);
223
223
  }
224
- static isFilterActive(entityName, filterName, filter, options) {
225
- if (filter.entity && !filter.entity.includes(entityName)) {
224
+ static isFilterActive(meta, filterName, filter, options) {
225
+ if (filter.entity && !filter.entity.includes(meta.className)) {
226
226
  return false;
227
227
  }
228
228
  if (options[filterName] === false) {
@@ -161,7 +161,7 @@ export class TransactionManager {
161
161
  const wrapped = helper(entity);
162
162
  const meta = wrapped.__meta;
163
163
  // eslint-disable-next-line dot-notation
164
- const parentEntity = parentUoW.getById(meta.className, wrapped.getPrimaryKey(), parent['_schema'], true);
164
+ const parentEntity = parentUoW.getById(meta.class, wrapped.getPrimaryKey(), parent['_schema'], true);
165
165
  if (parentEntity && parentEntity !== entity) {
166
166
  const parentWrapped = helper(parentEntity);
167
167
  parentWrapped.__data = wrapped.__data;
package/utils/Utils.d.ts CHANGED
@@ -110,7 +110,7 @@ export declare class Utils {
110
110
  /**
111
111
  * Gets string name of given class.
112
112
  */
113
- static className<T>(classOrName: EntityName<T>): string;
113
+ static className<T>(classOrName: string | EntityName<T>): string;
114
114
  static extractChildElements(items: string[], prefix: string, allSymbol?: string): string[];
115
115
  /**
116
116
  * Tries to detect TypeScript support.
package/utils/Utils.js CHANGED
@@ -35,7 +35,6 @@ export function compareObjects(a, b) {
35
35
  }
36
36
  /* v8 ignore next */
37
37
  if ((typeof a === 'function' && typeof b === 'function') ||
38
- (typeof a === 'object' && a.client && ['Ref', 'Raw'].includes(a.constructor.name) && typeof b === 'object' && b.client && ['Ref', 'Raw'].includes(b.constructor.name)) || // knex qb
39
38
  (a instanceof RegExp && b instanceof RegExp) ||
40
39
  (a instanceof String && b instanceof String) ||
41
40
  (a instanceof Number && b instanceof Number)) {
@@ -124,7 +123,7 @@ export function parseJsonSafe(value) {
124
123
  }
125
124
  export class Utils {
126
125
  static PK_SEPARATOR = '~~~';
127
- static #ORM_VERSION = '7.0.0-dev.114';
126
+ static #ORM_VERSION = '7.0.0-dev.116';
128
127
  /**
129
128
  * Checks if the argument is instance of `Object`. Returns false for arrays.
130
129
  */
package/utils/env-vars.js CHANGED
@@ -60,7 +60,6 @@ export function loadEnvironmentVars() {
60
60
  read1('warnWhenNoEntities', bool);
61
61
  read1('checkDuplicateTableNames', bool);
62
62
  read1('checkDuplicateFieldNames', bool);
63
- read1('checkDuplicateEntities', bool);
64
63
  read1('checkNonPersistentCompositeProps', bool);
65
64
  read1('inferDefaultValues', bool);
66
65
  read1('tsConfigPath');