@mikro-orm/core 7.0.17-dev.3 → 7.0.17-dev.5

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.js CHANGED
@@ -319,13 +319,13 @@ export class EntityManager {
319
319
  }
320
320
  const types = Object.values(meta.root.discriminatorMap).map(cls => this.metadata.get(cls));
321
321
  const children = [];
322
- const lookUpChildren = (ret, type) => {
323
- const children = types.filter(meta2 => meta2.extends === type);
324
- children.forEach(m => lookUpChildren(ret, m.class));
322
+ const lookUpChildren = (ret, parent) => {
323
+ const children = types.filter(meta2 => meta2.extends && this.metadata.find(meta2.extends) === parent);
324
+ children.forEach(m => lookUpChildren(ret, m));
325
325
  ret.push(...children.filter(c => c.discriminatorValue));
326
326
  return children;
327
327
  };
328
- lookUpChildren(children, meta.class);
328
+ lookUpChildren(children, meta);
329
329
  /* v8 ignore next */
330
330
  where[meta.root.discriminatorColumn] =
331
331
  children.length > 0
@@ -334,10 +334,10 @@ export class EntityLoader {
334
334
  fk = ownerProp.name;
335
335
  }
336
336
  }
337
- if (prop.kind === ReferenceKind.ONE_TO_ONE && !prop.owner && !ref) {
337
+ if (prop.kind === ReferenceKind.ONE_TO_ONE && !prop.owner && (!ref || (!prop.mapToPk && !populate.filter))) {
338
338
  children.length = 0;
339
339
  fk = meta.properties[prop.mappedBy].name;
340
- children.push(...this.filterByReferences(entities, prop.name, options.refresh));
340
+ children.push(...this.filterByReferences(entities, prop, options, ref));
341
341
  }
342
342
  if (children.length === 0) {
343
343
  return { items: [], partial };
@@ -753,12 +753,39 @@ export class EntityLoader {
753
753
  .filter(e => !e[field].__helper.__initialized)
754
754
  .map(e => Reference.unwrapReference(e[field]));
755
755
  }
756
- filterByReferences(entities, field, refresh) {
756
+ filterByReferences(entities, prop, options, ref) {
757
757
  /* v8 ignore next */
758
- if (refresh) {
758
+ if (options.refresh) {
759
759
  return entities;
760
760
  }
761
- return entities.filter(e => e[field] !== null && !e[field]?.__helper?.__initialized);
761
+ const field = prop.name;
762
+ return entities.filter(e => {
763
+ const value = e[field];
764
+ if (value === null) {
765
+ return false;
766
+ }
767
+ if (value === undefined || !Utils.isEntity(value, true)) {
768
+ return true;
769
+ }
770
+ const target = Reference.unwrapReference(value);
771
+ const wrapped = helper(target);
772
+ if (!wrapped.__initialized) {
773
+ return true;
774
+ }
775
+ if (ref) {
776
+ return false;
777
+ }
778
+ if (options.fields) {
779
+ const childFields = options.fields
780
+ .filter(f => f.startsWith(`${prop.name}.`))
781
+ .map(f => f.substring(prop.name.length + 1));
782
+ return childFields.length > 0 && !childFields.every(f => this.isPropertyLoaded(target, f));
783
+ }
784
+ return prop.targetMeta.comparableProps.some(targetProp => {
785
+ const inlineEmbedded = targetProp.kind === ReferenceKind.EMBEDDED && !targetProp.object;
786
+ return !inlineEmbedded && !targetProp.lazy && !wrapped.__loadedProperties.has(targetProp.name);
787
+ });
788
+ });
762
789
  }
763
790
  lookupAllRelationships(entityName) {
764
791
  const ret = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.0.17-dev.3",
3
+ "version": "7.0.17-dev.5",
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
  "keywords": [
6
6
  "data-mapper",
package/utils/Utils.js CHANGED
@@ -141,7 +141,7 @@ export function parseJsonSafe(value) {
141
141
  /** Collection of general-purpose utility methods used throughout the ORM. */
142
142
  export class Utils {
143
143
  static PK_SEPARATOR = '~~~';
144
- static #ORM_VERSION = '7.0.17-dev.3';
144
+ static #ORM_VERSION = '7.0.17-dev.5';
145
145
  /**
146
146
  * Checks if the argument is instance of `Object`. Returns false for arrays.
147
147
  */