@mikro-orm/sql 7.0.9-dev.1 → 7.0.9-dev.2
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.js +16 -1
- package/package.json +2 -2
- package/query/QueryBuilderHelper.js +1 -1
package/AbstractSqlDriver.js
CHANGED
|
@@ -1479,6 +1479,20 @@ export class AbstractSqlDriver extends DatabaseDriver {
|
|
|
1479
1479
|
: JoinType.leftJoin;
|
|
1480
1480
|
const schema = prop.targetMeta.schema === '*' ? (options?.schema ?? this.config.get('schema')) : prop.targetMeta.schema;
|
|
1481
1481
|
qb.join(field, tableAlias, {}, joinType, path, schema);
|
|
1482
|
+
// For relations to TPT child entities, INNER JOIN parent tables (GH #7469)
|
|
1483
|
+
if (meta2.inheritanceType === 'tpt' && meta2.tptParent) {
|
|
1484
|
+
let childAlias = tableAlias;
|
|
1485
|
+
let childMeta = meta2;
|
|
1486
|
+
while (childMeta.tptParent) {
|
|
1487
|
+
const parentMeta = childMeta.tptParent;
|
|
1488
|
+
const parentAlias = qb.getNextAlias(parentMeta.className);
|
|
1489
|
+
qb.createAlias(parentMeta.class, parentAlias);
|
|
1490
|
+
qb.state.tptAlias[`${tableAlias}:${parentMeta.className}`] = parentAlias;
|
|
1491
|
+
qb.addPropertyJoin(childMeta.tptParentProp, childAlias, parentAlias, JoinType.innerJoin, `${path}.[tpt]${childMeta.className}`);
|
|
1492
|
+
childAlias = parentAlias;
|
|
1493
|
+
childMeta = parentMeta;
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1482
1496
|
// For relations to TPT base classes, add LEFT JOINs for all child tables (polymorphic loading)
|
|
1483
1497
|
if (meta2.inheritanceType === 'tpt' && meta2.tptChildren?.length && !ref) {
|
|
1484
1498
|
// Use the registry metadata to ensure allTPTDescendants is available
|
|
@@ -1662,8 +1676,9 @@ export class AbstractSqlDriver extends DatabaseDriver {
|
|
|
1662
1676
|
const columns = meta.createColumnMappingObject(tableAlias);
|
|
1663
1677
|
return [raw(`${this.evaluateFormula(prop.formula, columns, table)} as ${aliased}`)];
|
|
1664
1678
|
}
|
|
1679
|
+
const sourceAlias = qb.helper.getTPTAliasForProperty(prop.name, tableAlias);
|
|
1665
1680
|
return prop.fieldNames.map(fieldName => {
|
|
1666
|
-
return raw('?? as ??', [`${
|
|
1681
|
+
return raw('?? as ??', [`${sourceAlias}.${fieldName}`, `${tableAlias}__${fieldName}`]);
|
|
1667
1682
|
});
|
|
1668
1683
|
}
|
|
1669
1684
|
/** @internal */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sql",
|
|
3
|
-
"version": "7.0.9-dev.
|
|
3
|
+
"version": "7.0.9-dev.2",
|
|
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.0.8"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.0.9-dev.
|
|
56
|
+
"@mikro-orm/core": "7.0.9-dev.2"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|
|
@@ -40,7 +40,7 @@ export class QueryBuilderHelper {
|
|
|
40
40
|
// Walk up the TPT hierarchy to find which parent owns this property
|
|
41
41
|
let parentMeta = meta.tptParent;
|
|
42
42
|
while (parentMeta) {
|
|
43
|
-
const parentAlias = this.#tptAliasMap[parentMeta.className];
|
|
43
|
+
const parentAlias = this.#tptAliasMap[`${defaultAlias}:${parentMeta.className}`] ?? this.#tptAliasMap[parentMeta.className];
|
|
44
44
|
if (parentAlias && parentMeta.ownProps?.some(p => p.name === propName || p.fieldNames?.includes(propName))) {
|
|
45
45
|
return parentAlias;
|
|
46
46
|
}
|