@mikro-orm/sql 7.0.16-dev.9 → 7.0.17-dev.0
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 +7 -0
- package/AbstractSqlDriver.js +27 -11
- package/package.json +4 -4
package/AbstractSqlDriver.d.ts
CHANGED
|
@@ -101,6 +101,13 @@ export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlCo
|
|
|
101
101
|
mergeJoinedResult<T extends object>(rawResults: EntityData<T>[], meta: EntityMetadata<T>, joinedProps: PopulateOptions<T>[]): EntityData<T>[];
|
|
102
102
|
protected shouldHaveColumn<T, U>(meta: EntityMetadata<T>, prop: EntityProperty<U>, populate: readonly PopulateOptions<U>[], fields?: readonly InternalField<U>[], exclude?: readonly InternalField<U>[]): boolean;
|
|
103
103
|
protected getFieldsForJoinedLoad<T extends object>(qb: AnyQueryBuilder<T>, meta: EntityMetadata<T>, options: FieldsForJoinedLoadOptions<T>): InternalField<T>[];
|
|
104
|
+
/**
|
|
105
|
+
* Walks the TPT inheritance chain of `leafMeta` and INNER JOINs each parent table.
|
|
106
|
+
* Registers the parent aliases in `qb.state.tptAlias` so column resolution finds them
|
|
107
|
+
* when filter conditions reference parent-table columns.
|
|
108
|
+
* @internal
|
|
109
|
+
*/
|
|
110
|
+
protected addTPTParentJoinsForRelation<T extends object>(qb: AnyQueryBuilder<T>, leafMeta: EntityMetadata, leafAlias: string, basePath: string): void;
|
|
104
111
|
/**
|
|
105
112
|
* Adds LEFT JOINs and fields for TPT polymorphic loading when populating a relation to a TPT base class.
|
|
106
113
|
* @internal
|
package/AbstractSqlDriver.js
CHANGED
|
@@ -1443,6 +1443,13 @@ export class AbstractSqlDriver extends DatabaseDriver {
|
|
|
1443
1443
|
const targetPath = `${pathPrefix}${basePath}[${targetMeta.className}]`;
|
|
1444
1444
|
const schema = targetMeta.schema === '*' ? (options?.schema ?? this.config.get('schema')) : targetMeta.schema;
|
|
1445
1445
|
qb.addPolymorphicJoin(prop, targetMeta, options.parentTableAlias, tableAlias, JoinType.leftJoin, targetPath, schema);
|
|
1446
|
+
// For polymorphic targets that are TPT child entities, INNER JOIN parent tables so that
|
|
1447
|
+
// filter conditions referencing parent-table columns resolve to the correct alias. The
|
|
1448
|
+
// INNER JOINs get nested inside the polymorphic LEFT JOIN by processNestedJoins, which
|
|
1449
|
+
// keeps the resulting query valid for rows pointing to other polymorphic targets.
|
|
1450
|
+
if (targetMeta.inheritanceType === 'tpt' && targetMeta.tptParent) {
|
|
1451
|
+
this.addTPTParentJoinsForRelation(qb, targetMeta, tableAlias, targetPath);
|
|
1452
|
+
}
|
|
1446
1453
|
// For polymorphic targets that are TPT base classes, also LEFT JOIN
|
|
1447
1454
|
// all descendant tables so child-specific fields can be selected.
|
|
1448
1455
|
if (targetMeta.inheritanceType === 'tpt' && targetMeta.tptChildren?.length && !ref) {
|
|
@@ -1491,17 +1498,7 @@ export class AbstractSqlDriver extends DatabaseDriver {
|
|
|
1491
1498
|
qb.join(field, tableAlias, {}, joinType, path, schema);
|
|
1492
1499
|
// For relations to TPT child entities, INNER JOIN parent tables (GH #7469)
|
|
1493
1500
|
if (meta2.inheritanceType === 'tpt' && meta2.tptParent) {
|
|
1494
|
-
|
|
1495
|
-
let childMeta = meta2;
|
|
1496
|
-
while (childMeta.tptParent) {
|
|
1497
|
-
const parentMeta = childMeta.tptParent;
|
|
1498
|
-
const parentAlias = qb.getNextAlias(parentMeta.className);
|
|
1499
|
-
qb.createAlias(parentMeta.class, parentAlias);
|
|
1500
|
-
qb.state.tptAlias[`${tableAlias}:${parentMeta.className}`] = parentAlias;
|
|
1501
|
-
qb.addPropertyJoin(childMeta.tptParentProp, childAlias, parentAlias, JoinType.innerJoin, `${path}.[tpt]${childMeta.className}`);
|
|
1502
|
-
childAlias = parentAlias;
|
|
1503
|
-
childMeta = parentMeta;
|
|
1504
|
-
}
|
|
1501
|
+
this.addTPTParentJoinsForRelation(qb, meta2, tableAlias, path);
|
|
1505
1502
|
}
|
|
1506
1503
|
// For relations to TPT base classes, add LEFT JOINs for all child tables (polymorphic loading)
|
|
1507
1504
|
if (meta2.inheritanceType === 'tpt' && meta2.tptChildren?.length && !ref) {
|
|
@@ -1549,6 +1546,25 @@ export class AbstractSqlDriver extends DatabaseDriver {
|
|
|
1549
1546
|
}
|
|
1550
1547
|
return fields;
|
|
1551
1548
|
}
|
|
1549
|
+
/**
|
|
1550
|
+
* Walks the TPT inheritance chain of `leafMeta` and INNER JOINs each parent table.
|
|
1551
|
+
* Registers the parent aliases in `qb.state.tptAlias` so column resolution finds them
|
|
1552
|
+
* when filter conditions reference parent-table columns.
|
|
1553
|
+
* @internal
|
|
1554
|
+
*/
|
|
1555
|
+
addTPTParentJoinsForRelation(qb, leafMeta, leafAlias, basePath) {
|
|
1556
|
+
let childAlias = leafAlias;
|
|
1557
|
+
let childMeta = leafMeta;
|
|
1558
|
+
while (childMeta.tptParent) {
|
|
1559
|
+
const parentMeta = childMeta.tptParent;
|
|
1560
|
+
const parentAlias = qb.getNextAlias(parentMeta.className);
|
|
1561
|
+
qb.createAlias(parentMeta.class, parentAlias);
|
|
1562
|
+
qb.state.tptAlias[`${leafAlias}:${parentMeta.className}`] = parentAlias;
|
|
1563
|
+
qb.addPropertyJoin(childMeta.tptParentProp, childAlias, parentAlias, JoinType.innerJoin, `${basePath}.[tpt]${childMeta.className}`);
|
|
1564
|
+
childAlias = parentAlias;
|
|
1565
|
+
childMeta = parentMeta;
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1552
1568
|
/**
|
|
1553
1569
|
* Adds LEFT JOINs and fields for TPT polymorphic loading when populating a relation to a TPT base class.
|
|
1554
1570
|
* @internal
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sql",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.17-dev.0",
|
|
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",
|
|
@@ -47,13 +47,13 @@
|
|
|
47
47
|
"copy": "node ../../scripts/copy.mjs"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"kysely": "0.
|
|
50
|
+
"kysely": "0.29.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@mikro-orm/core": "^7.0.
|
|
53
|
+
"@mikro-orm/core": "^7.0.16"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.0.
|
|
56
|
+
"@mikro-orm/core": "7.0.17-dev.0"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|