@mikro-orm/sql 7.1.9-dev.23 → 7.1.9-dev.24
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 +18 -6
- package/package.json +2 -2
package/AbstractSqlDriver.js
CHANGED
|
@@ -1337,10 +1337,15 @@ export class AbstractSqlDriver extends DatabaseDriver {
|
|
|
1337
1337
|
async loadPolymorphicPivotOwnerSide(prop, owners, where, orderBy, ctx, options, pivotJoin, inverseProp) {
|
|
1338
1338
|
const pivotMeta = this.metadata.get(prop.pivotEntity);
|
|
1339
1339
|
const targetMeta = prop.targetMeta;
|
|
1340
|
-
//
|
|
1340
|
+
// `prop.discriminator` spans all owner FK columns but carries no target metadata, so a composite
|
|
1341
|
+
// owner PK neither expands to a tuple condition nor gets mapped back; the virtual M:1 relation
|
|
1342
|
+
// to this discriminator's owner describes the same columns as an actual relation
|
|
1343
|
+
const ownerMeta = this.metadata.get(pivotMeta.polymorphicDiscriminatorMap[prop.discriminatorValue]);
|
|
1344
|
+
const ownerProp = pivotMeta.properties[`${prop.discriminator}_${ownerMeta.tableName}`];
|
|
1345
|
+
// Build condition: discriminator = 'post' AND {owner} IN (...)
|
|
1341
1346
|
const cond = {
|
|
1342
1347
|
[prop.discriminatorColumn]: prop.discriminatorValue,
|
|
1343
|
-
[
|
|
1348
|
+
[ownerProp.name]: { $in: owners.length === 1 && owners[0].length === 1 ? owners.map(o => o[0]) : owners },
|
|
1344
1349
|
};
|
|
1345
1350
|
if (!Utils.isEmpty(where)) {
|
|
1346
1351
|
cond[inverseProp.name] = { ...where };
|
|
@@ -1351,9 +1356,12 @@ export class AbstractSqlDriver extends DatabaseDriver {
|
|
|
1351
1356
|
const childExclude = !Utils.isEmpty(options?.exclude)
|
|
1352
1357
|
? options.exclude.map(f => `${inverseProp.name}.${f}`)
|
|
1353
1358
|
: [];
|
|
1359
|
+
// the owner relation is virtual, so the FK columns have to be selected via the per-column pivot
|
|
1360
|
+
// props a composite owner PK gets; a single column owner PK is covered by the flat prop itself
|
|
1361
|
+
const ownerFields = ownerMeta.compositePK ? prop.joinColumns : [prop.discriminator];
|
|
1354
1362
|
const fields = pivotJoin
|
|
1355
|
-
? [inverseProp.name,
|
|
1356
|
-
: [inverseProp.name,
|
|
1363
|
+
? [inverseProp.name, ...ownerFields, prop.discriminatorColumn]
|
|
1364
|
+
: [inverseProp.name, ...ownerFields, prop.discriminatorColumn, ...childFields];
|
|
1357
1365
|
const res = await this.find(pivotMeta.class, cond, {
|
|
1358
1366
|
ctx,
|
|
1359
1367
|
...options,
|
|
@@ -1374,7 +1382,7 @@ export class AbstractSqlDriver extends DatabaseDriver {
|
|
|
1374
1382
|
_populateWhere: 'infer',
|
|
1375
1383
|
populateFilter: this.wrapPopulateFilter(options, inverseProp.name),
|
|
1376
1384
|
});
|
|
1377
|
-
return this.buildPivotResultMap(owners, res,
|
|
1385
|
+
return this.buildPivotResultMap(owners, res, ownerProp.name, inverseProp.name, ownerMeta);
|
|
1378
1386
|
}
|
|
1379
1387
|
/**
|
|
1380
1388
|
* Load from inverse side of polymorphic M:N (e.g., Tag -> Posts)
|
|
@@ -1671,7 +1679,11 @@ export class AbstractSqlDriver extends DatabaseDriver {
|
|
|
1671
1679
|
if (pivotRelations.length > 0) {
|
|
1672
1680
|
pk = Utils.getPrimaryKeyHash([
|
|
1673
1681
|
pk,
|
|
1674
|
-
...pivotRelations.
|
|
1682
|
+
...pivotRelations.flatMap(p => {
|
|
1683
|
+
const value = item[p.name];
|
|
1684
|
+
// composite FKs are mapped to an array of values, which `extractPK` does not accept
|
|
1685
|
+
return (Array.isArray(value) ? value : Utils.extractPK(value, p.targetMeta));
|
|
1686
|
+
}),
|
|
1675
1687
|
]);
|
|
1676
1688
|
}
|
|
1677
1689
|
if (map[pk]) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sql",
|
|
3
|
-
"version": "7.1.9-dev.
|
|
3
|
+
"version": "7.1.9-dev.24",
|
|
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.8"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.1.9-dev.
|
|
56
|
+
"@mikro-orm/core": "7.1.9-dev.24"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|