@mikro-orm/sql 7.2.5-dev.8 → 7.2.5
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
CHANGED
|
@@ -853,10 +853,16 @@ export class AbstractSqlDriver extends DatabaseDriver {
|
|
|
853
853
|
// the map misses subtypes whose props were not initialized yet during discovery (root column owner, grandchildren)
|
|
854
854
|
const discriminator = row[meta.discriminatorColumn];
|
|
855
855
|
const childClass = meta.discriminatorMap?.[discriminator];
|
|
856
|
-
const
|
|
857
|
-
|
|
856
|
+
const childProp = childClass && this.metadata.find(childClass)?.properties[prop.name];
|
|
857
|
+
const activeField = prop.stiFieldNameMap[discriminator] ?? childProp?.fieldNames[0];
|
|
858
858
|
for (const field of prop.stiFieldNames) {
|
|
859
|
-
|
|
859
|
+
// the subtype's own property, as siblings can declare it with a different type or embeddable
|
|
860
|
+
if (field === activeField) {
|
|
861
|
+
addParams(childProp ?? prop, row);
|
|
862
|
+
}
|
|
863
|
+
else {
|
|
864
|
+
params.push(null);
|
|
865
|
+
}
|
|
860
866
|
keys.push('?');
|
|
861
867
|
}
|
|
862
868
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sql",
|
|
3
|
-
"version": "7.2.5
|
|
3
|
+
"version": "7.2.5",
|
|
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",
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
"kysely": "0.29.6"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@mikro-orm/core": "^7.2.
|
|
53
|
+
"@mikro-orm/core": "^7.2.5"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.2.5
|
|
56
|
+
"@mikro-orm/core": "7.2.5"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|
package/query/QueryBuilder.js
CHANGED
|
@@ -1873,20 +1873,7 @@ export class QueryBuilder {
|
|
|
1873
1873
|
if (meta.root.inheritanceType !== 'sti' || !meta.discriminatorValue) {
|
|
1874
1874
|
return;
|
|
1875
1875
|
}
|
|
1876
|
-
|
|
1877
|
-
const children = [];
|
|
1878
|
-
const lookUpChildren = (ret, parent) => {
|
|
1879
|
-
const children = types.filter(meta2 => meta2.extends && this.metadata.find(meta2.extends) === parent);
|
|
1880
|
-
children.forEach(m => lookUpChildren(ret, m));
|
|
1881
|
-
ret.push(...children.filter(c => c.discriminatorValue));
|
|
1882
|
-
return children;
|
|
1883
|
-
};
|
|
1884
|
-
lookUpChildren(children, meta);
|
|
1885
|
-
this.andWhere({
|
|
1886
|
-
[meta.root.discriminatorColumn]: children.length > 0
|
|
1887
|
-
? { $in: [meta.discriminatorValue, ...children.map(c => c.discriminatorValue)] }
|
|
1888
|
-
: meta.discriminatorValue,
|
|
1889
|
-
});
|
|
1876
|
+
this.andWhere({ [meta.root.discriminatorColumn]: this.helper.getDiscriminatorCondition(meta) });
|
|
1890
1877
|
}
|
|
1891
1878
|
/**
|
|
1892
1879
|
* Ensures TPT joins are applied. Can be called early before finalize() to populate
|
|
@@ -30,6 +30,8 @@ export declare class QueryBuilderHelper {
|
|
|
30
30
|
sql: string;
|
|
31
31
|
params: unknown[];
|
|
32
32
|
};
|
|
33
|
+
/** STI discriminator condition matching the entity and all its subclasses. */
|
|
34
|
+
getDiscriminatorCondition(meta: EntityMetadata): unknown;
|
|
33
35
|
mapJoinColumns(type: QueryType, join: JoinOptions): (string | Raw)[];
|
|
34
36
|
isOneToOneInverse(field: string, meta?: EntityMetadata): boolean;
|
|
35
37
|
getTableName(entityName: EntityName): string;
|
|
@@ -296,7 +296,7 @@ export class QueryBuilderHelper {
|
|
|
296
296
|
!join.path?.endsWith('[pivot]')) {
|
|
297
297
|
const typeProperty = join.prop.targetMeta.root.discriminatorColumn;
|
|
298
298
|
const alias = join.inverseAlias ?? join.alias;
|
|
299
|
-
join.cond[`${alias}.${typeProperty}`] = join.prop.targetMeta
|
|
299
|
+
join.cond[`${alias}.${typeProperty}`] = this.getDiscriminatorCondition(join.prop.targetMeta);
|
|
300
300
|
}
|
|
301
301
|
// For polymorphic relations, add discriminator condition to filter by target entity type
|
|
302
302
|
if (join.prop.polymorphic && join.prop.discriminatorColumn && join.prop.discriminatorMap) {
|
|
@@ -341,6 +341,22 @@ export class QueryBuilderHelper {
|
|
|
341
341
|
}
|
|
342
342
|
return { sql, params };
|
|
343
343
|
}
|
|
344
|
+
/** STI discriminator condition matching the entity and all its subclasses. */
|
|
345
|
+
getDiscriminatorCondition(meta) {
|
|
346
|
+
const types = Object.values(meta.root.discriminatorMap).map(cls => this.#metadata.get(cls));
|
|
347
|
+
const children = [];
|
|
348
|
+
const lookUpChildren = (ret, parent) => {
|
|
349
|
+
const children = types.filter(meta2 => meta2.extends && this.#metadata.find(meta2.extends) === parent);
|
|
350
|
+
children.forEach(m => lookUpChildren(ret, m));
|
|
351
|
+
ret.push(...children.filter(c => c.discriminatorValue));
|
|
352
|
+
return children;
|
|
353
|
+
};
|
|
354
|
+
// resolve from storage, `prop.targetMeta` can be a copy that fails the identity check above
|
|
355
|
+
lookUpChildren(children, this.#metadata.get(meta.class));
|
|
356
|
+
return children.length > 0
|
|
357
|
+
? { $in: [meta.discriminatorValue, ...children.map(c => c.discriminatorValue)] }
|
|
358
|
+
: meta.discriminatorValue;
|
|
359
|
+
}
|
|
344
360
|
mapJoinColumns(type, join) {
|
|
345
361
|
if (join.prop && [ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(join.prop.kind)) {
|
|
346
362
|
return join.prop.fieldNames.map((_fieldName, idx) => {
|