@mikro-orm/core 7.0.17-dev.2 → 7.0.17-dev.4

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.
@@ -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 = [];
@@ -587,6 +587,10 @@ export class MetadataDiscovery {
587
587
  prop.pivotEntity = pivotMeta.class;
588
588
  if (prop.inversedBy) {
589
589
  prop.targetMeta.properties[prop.inversedBy].pivotEntity = pivotMeta.class;
590
+ const targetRoot = prop.targetMeta.root;
591
+ if (targetRoot !== prop.targetMeta && targetRoot.properties[prop.inversedBy]) {
592
+ targetRoot.properties[prop.inversedBy].pivotEntity = pivotMeta.class;
593
+ }
590
594
  }
591
595
  return pivotMeta;
592
596
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.0.17-dev.2",
3
+ "version": "7.0.17-dev.4",
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.2';
144
+ static #ORM_VERSION = '7.0.17-dev.4';
145
145
  /**
146
146
  * Checks if the argument is instance of `Object`. Returns false for arrays.
147
147
  */