@mikro-orm/sql 7.1.15-dev.18 → 7.1.15-dev.19
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/AbstractSqlDriver.d.ts +0 -7
- package/AbstractSqlDriver.js +1 -24
- package/package.json +2 -2
- package/query/QueryBuilder.d.ts +7 -0
- package/query/QueryBuilder.js +27 -1
package/AbstractSqlDriver.d.ts
CHANGED
|
@@ -118,13 +118,6 @@ export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlCo
|
|
|
118
118
|
mergeJoinedResult<T extends object>(rawResults: EntityData<T>[], meta: EntityMetadata<T>, joinedProps: PopulateOptions<T>[]): EntityData<T>[];
|
|
119
119
|
protected shouldHaveColumn<T, U>(meta: EntityMetadata<T>, prop: EntityProperty<U>, populate: readonly PopulateOptions<U>[], fields?: readonly InternalField<U>[], exclude?: readonly InternalField<U>[]): boolean;
|
|
120
120
|
protected getFieldsForJoinedLoad<T extends object>(qb: AnyQueryBuilder<T>, meta: EntityMetadata<T>, options: FieldsForJoinedLoadOptions<T>): InternalField<T>[];
|
|
121
|
-
/**
|
|
122
|
-
* Walks the TPT inheritance chain of `leafMeta` and INNER JOINs each parent table.
|
|
123
|
-
* Registers the parent aliases in `qb.state.tptAlias` so column resolution finds them
|
|
124
|
-
* when filter conditions reference parent-table columns.
|
|
125
|
-
* @internal
|
|
126
|
-
*/
|
|
127
|
-
protected addTPTParentJoinsForRelation<T extends object>(qb: AnyQueryBuilder<T>, leafMeta: EntityMetadata, leafAlias: string, basePath: string): void;
|
|
128
121
|
/**
|
|
129
122
|
* Adds LEFT JOINs and fields for TPT polymorphic loading when populating a relation to a TPT base class.
|
|
130
123
|
* @internal
|
package/AbstractSqlDriver.js
CHANGED
|
@@ -1817,7 +1817,7 @@ export class AbstractSqlDriver extends DatabaseDriver {
|
|
|
1817
1817
|
// INNER JOINs get nested inside the polymorphic LEFT JOIN by processNestedJoins, which
|
|
1818
1818
|
// keeps the resulting query valid for rows pointing to other polymorphic targets.
|
|
1819
1819
|
if (targetMeta.inheritanceType === 'tpt' && targetMeta.tptParent) {
|
|
1820
|
-
|
|
1820
|
+
qb.addTPTParentJoins(targetMeta, tableAlias, targetPath);
|
|
1821
1821
|
}
|
|
1822
1822
|
// For polymorphic targets that are TPT base classes, also LEFT JOIN
|
|
1823
1823
|
// all descendant tables so child-specific fields can be selected.
|
|
@@ -1865,10 +1865,6 @@ export class AbstractSqlDriver extends DatabaseDriver {
|
|
|
1865
1865
|
: JoinType.leftJoin;
|
|
1866
1866
|
const schema = prop.targetMeta.schema === '*' ? (options?.schema ?? this.config.get('schema')) : prop.targetMeta.schema;
|
|
1867
1867
|
qb.join(field, tableAlias, {}, joinType, path, schema);
|
|
1868
|
-
// For relations to TPT child entities, INNER JOIN parent tables (GH #7469)
|
|
1869
|
-
if (meta2.inheritanceType === 'tpt' && meta2.tptParent) {
|
|
1870
|
-
this.addTPTParentJoinsForRelation(qb, meta2, tableAlias, path);
|
|
1871
|
-
}
|
|
1872
1868
|
// For relations to TPT base classes, add LEFT JOINs for all child tables (polymorphic loading)
|
|
1873
1869
|
if (meta2.inheritanceType === 'tpt' && meta2.tptChildren?.length && !ref) {
|
|
1874
1870
|
// Use the registry metadata to ensure allTPTDescendants is available
|
|
@@ -1915,25 +1911,6 @@ export class AbstractSqlDriver extends DatabaseDriver {
|
|
|
1915
1911
|
}
|
|
1916
1912
|
return fields;
|
|
1917
1913
|
}
|
|
1918
|
-
/**
|
|
1919
|
-
* Walks the TPT inheritance chain of `leafMeta` and INNER JOINs each parent table.
|
|
1920
|
-
* Registers the parent aliases in `qb.state.tptAlias` so column resolution finds them
|
|
1921
|
-
* when filter conditions reference parent-table columns.
|
|
1922
|
-
* @internal
|
|
1923
|
-
*/
|
|
1924
|
-
addTPTParentJoinsForRelation(qb, leafMeta, leafAlias, basePath) {
|
|
1925
|
-
let childAlias = leafAlias;
|
|
1926
|
-
let childMeta = leafMeta;
|
|
1927
|
-
while (childMeta.tptParent) {
|
|
1928
|
-
const parentMeta = childMeta.tptParent;
|
|
1929
|
-
const parentAlias = qb.getNextAlias(parentMeta.className);
|
|
1930
|
-
qb.createAlias(parentMeta.class, parentAlias);
|
|
1931
|
-
qb.state.tptAlias[`${leafAlias}:${parentMeta.className}`] = parentAlias;
|
|
1932
|
-
qb.addPropertyJoin(childMeta.tptParentProp, childAlias, parentAlias, JoinType.innerJoin, `${basePath}.[tpt]${childMeta.className}`);
|
|
1933
|
-
childAlias = parentAlias;
|
|
1934
|
-
childMeta = parentMeta;
|
|
1935
|
-
}
|
|
1936
|
-
}
|
|
1937
1914
|
/**
|
|
1938
1915
|
* Adds LEFT JOINs and fields for TPT polymorphic loading when populating a relation to a TPT base class.
|
|
1939
1916
|
* @internal
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sql",
|
|
3
|
-
"version": "7.1.15-dev.
|
|
3
|
+
"version": "7.1.15-dev.19",
|
|
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.
|
|
56
|
+
"@mikro-orm/core": "7.1.15-dev.19"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|
package/query/QueryBuilder.d.ts
CHANGED
|
@@ -950,6 +950,13 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
950
950
|
*/
|
|
951
951
|
addPropertyJoin(prop: EntityProperty, ownerAlias: string, alias: string, type: JoinType, path: string, schema?: string): string;
|
|
952
952
|
private joinReference;
|
|
953
|
+
/**
|
|
954
|
+
* Walks the TPT inheritance chain of `leafMeta` and INNER JOINs each parent table.
|
|
955
|
+
* Registers the parent aliases in `state.tptAlias` so column resolution finds them
|
|
956
|
+
* when conditions reference parent-table columns.
|
|
957
|
+
* @internal
|
|
958
|
+
*/
|
|
959
|
+
addTPTParentJoins(leafMeta: EntityMetadata, leafAlias: string, basePath: string): void;
|
|
953
960
|
protected prepareFields<T>(fields: InternalField<T>[], type?: 'where' | 'groupBy' | 'sub-query', schema?: string): (string | RawQueryFragment)[];
|
|
954
961
|
/**
|
|
955
962
|
* Resolves nested paths like `a.books.title` to their actual field references.
|
package/query/QueryBuilder.js
CHANGED
|
@@ -495,7 +495,10 @@ export class QueryBuilder {
|
|
|
495
495
|
return cond.some(c => this.condReferencesAlias(c, alias));
|
|
496
496
|
}
|
|
497
497
|
if (Utils.isPlainObject(cond)) {
|
|
498
|
-
return Object.entries(cond).some(([key, value]) =>
|
|
498
|
+
return Object.entries(cond).some(([key, value]) => {
|
|
499
|
+
const [keyAlias, field] = this.helper.splitField(key);
|
|
500
|
+
return this.helper.getTPTAliasForProperty(field, keyAlias) === alias || this.condReferencesAlias(value, alias);
|
|
501
|
+
});
|
|
499
502
|
}
|
|
500
503
|
return false;
|
|
501
504
|
}
|
|
@@ -1495,9 +1498,31 @@ export class QueryBuilder {
|
|
|
1495
1498
|
this.#state.joins[aliasedName] = this.helper.joinManyToOneReference(prop, ownerAlias, alias, type, cond, schema);
|
|
1496
1499
|
this.#state.joins[aliasedName].path ??= path;
|
|
1497
1500
|
}
|
|
1501
|
+
if (prop.targetMeta.inheritanceType === 'tpt' && prop.targetMeta.tptParent) {
|
|
1502
|
+
this.addTPTParentJoins(prop.targetMeta, alias, path);
|
|
1503
|
+
}
|
|
1498
1504
|
this.nestReferencedJoins(this.#state.joins[aliasedName]);
|
|
1499
1505
|
return { prop, key: aliasedName };
|
|
1500
1506
|
}
|
|
1507
|
+
/**
|
|
1508
|
+
* Walks the TPT inheritance chain of `leafMeta` and INNER JOINs each parent table.
|
|
1509
|
+
* Registers the parent aliases in `state.tptAlias` so column resolution finds them
|
|
1510
|
+
* when conditions reference parent-table columns.
|
|
1511
|
+
* @internal
|
|
1512
|
+
*/
|
|
1513
|
+
addTPTParentJoins(leafMeta, leafAlias, basePath) {
|
|
1514
|
+
let childAlias = leafAlias;
|
|
1515
|
+
let childMeta = leafMeta;
|
|
1516
|
+
while (childMeta.tptParent) {
|
|
1517
|
+
const parentMeta = childMeta.tptParent;
|
|
1518
|
+
const parentAlias = this.getNextAlias(parentMeta.className);
|
|
1519
|
+
this.createAlias(parentMeta.class, parentAlias);
|
|
1520
|
+
this.#state.tptAlias[`${leafAlias}:${parentMeta.className}`] = parentAlias;
|
|
1521
|
+
this.addPropertyJoin(childMeta.tptParentProp, childAlias, parentAlias, JoinType.innerJoin, `${basePath}.[tpt]${childMeta.className}`);
|
|
1522
|
+
childAlias = parentAlias;
|
|
1523
|
+
childMeta = parentMeta;
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1501
1526
|
prepareFields(fields, type = 'where', schema) {
|
|
1502
1527
|
const ret = [];
|
|
1503
1528
|
const getFieldName = (name, customAlias) => {
|
|
@@ -2087,6 +2112,7 @@ export class QueryBuilder {
|
|
|
2087
2112
|
else {
|
|
2088
2113
|
join.cond = { ...join.cond, [k]: cond[k] };
|
|
2089
2114
|
}
|
|
2115
|
+
this.nestReferencedJoins(join);
|
|
2090
2116
|
}
|
|
2091
2117
|
}
|
|
2092
2118
|
}
|