@mikro-orm/sql 7.1.15-dev.0 → 7.1.15-dev.10

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.
@@ -1649,6 +1649,11 @@ export class AbstractSqlDriver extends DatabaseDriver {
1649
1649
  if (prop.kind === ReferenceKind.ONE_TO_ONE && prop.mapToPk && prop.owner) {
1650
1650
  return false;
1651
1651
  }
1652
+ // Polymorphic to-one flattened from an object embeddable lives inside a JSON column, so the join
1653
+ // conditions would need JSON extraction for both the discriminator and the FK; fall back to SELECT_IN.
1654
+ if (prop.polymorphic && prop.object && prop.embedded) {
1655
+ return false;
1656
+ }
1652
1657
  if (strategy !== LoadStrategy.JOINED) {
1653
1658
  // force joined strategy for explicit 1:1 owner populate hint as it would require a join anyway
1654
1659
  return prop.kind === ReferenceKind.ONE_TO_ONE && !prop.owner;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/sql",
3
- "version": "7.1.15-dev.0",
3
+ "version": "7.1.15-dev.10",
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",
@@ -53,7 +53,7 @@
53
53
  "@mikro-orm/core": "^7.1.14"
54
54
  },
55
55
  "peerDependencies": {
56
- "@mikro-orm/core": "7.1.15-dev.0"
56
+ "@mikro-orm/core": "7.1.15-dev.10"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">= 22.17.0"
@@ -782,6 +782,8 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
782
782
  * @internal
783
783
  */
784
784
  getJoinForPath(path: string, options?: ICriteriaNodeProcessOptions): JoinOptions | undefined;
785
+ /** Branch-insensitive path matching still must not cross branches — segments with different explicit branch markers (e.g. `Mobile[0]` vs `Mobile[1]`) belong to sibling joins. */
786
+ private branchesConflict;
785
787
  /**
786
788
  * @internal
787
789
  */
@@ -397,7 +397,10 @@ export class QueryBuilder {
397
397
  * @internal
398
398
  */
399
399
  scheduleFilterCheck(path) {
400
- this.#state.autoJoinedPaths.push(path);
400
+ // deduplicate so filters forming a relation cycle cannot reschedule an already visited path forever
401
+ if (!this.#state.autoJoinedPaths.includes(path)) {
402
+ this.#state.autoJoinedPaths.push(path);
403
+ }
401
404
  }
402
405
  /**
403
406
  * @internal
@@ -990,12 +993,13 @@ export class QueryBuilder {
990
993
  }
991
994
  if (!join && options?.ignoreBranching) {
992
995
  join = joins.find(j => {
993
- return j.path?.replace(/\[\d+]/g, '') === path.replace(/\[\d+]/g, '');
996
+ return j.path?.replace(/\[\d+]/g, '') === path.replace(/\[\d+]/g, '') && !this.branchesConflict(j.path, path);
994
997
  });
995
998
  }
996
999
  if (!join && options?.matchPopulateJoins && options?.ignoreBranching) {
997
1000
  join = joins.find(j => {
998
- return j.path?.replace(/\[\d+]|\[populate]/g, '') === path.replace(/\[\d+]|\[populate]/g, '');
1001
+ return (j.path?.replace(/\[\d+]|\[populate]/g, '') === path.replace(/\[\d+]|\[populate]/g, '') &&
1002
+ !this.branchesConflict(j.path, path));
999
1003
  });
1000
1004
  }
1001
1005
  if (!join && options?.matchPopulateJoins) {
@@ -1005,6 +1009,12 @@ export class QueryBuilder {
1005
1009
  }
1006
1010
  return join;
1007
1011
  }
1012
+ /** Branch-insensitive path matching still must not cross branches — segments with different explicit branch markers (e.g. `Mobile[0]` vs `Mobile[1]`) belong to sibling joins. */
1013
+ branchesConflict(path1, path2) {
1014
+ const markers = (path) => path.split('.').map(segment => /\[(\d+)]/.exec(segment)?.[1]);
1015
+ const markers2 = markers(path2);
1016
+ return markers(path1).some((m, idx) => m != null && markers2[idx] != null && m !== markers2[idx]);
1017
+ }
1008
1018
  /**
1009
1019
  * @internal
1010
1020
  */