@mikro-orm/core 7.1.15-dev.7 → 7.1.15-dev.8
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/entity/EntityLoader.js
CHANGED
|
@@ -229,9 +229,10 @@ export class EntityLoader {
|
|
|
229
229
|
}
|
|
230
230
|
toPopulate.push(entity);
|
|
231
231
|
}
|
|
232
|
-
else if (refValue == null && !helper(entity).__loadedProperties.has(prop.name)) {
|
|
232
|
+
else if (refValue == null && !prop.object && !helper(entity).__loadedProperties.has(prop.name)) {
|
|
233
233
|
// FK columns weren't loaded (partial loading) — need to re-fetch them.
|
|
234
234
|
// If the property IS in __loadedProperties, the FK was loaded and is genuinely null.
|
|
235
|
+
// Object-embedded virtual props are skipped — they are populated via the embeddable instance.
|
|
235
236
|
needsFkLoad.push(entity);
|
|
236
237
|
}
|
|
237
238
|
}
|
|
@@ -441,7 +441,18 @@ export class MetadataDiscovery {
|
|
|
441
441
|
if (prop.kind === ReferenceKind.SCALAR || prop.kind === ReferenceKind.EMBEDDED) {
|
|
442
442
|
prop.fieldNames = [this.#namingStrategy.propertyToColumnName(prop.name, object)];
|
|
443
443
|
}
|
|
444
|
-
else if ([ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind) &&
|
|
444
|
+
else if ([ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind) && prop.polymorphic) {
|
|
445
|
+
if (prop.targetMeta) {
|
|
446
|
+
// same layout as `initManyToOneFields` builds later: `[discriminatorColumn, ...fkIdColumns]`
|
|
447
|
+
const pkFields = prop.targetMeta.getPrimaryProps().flatMap(pk => {
|
|
448
|
+
this.initFieldName(pk);
|
|
449
|
+
return pk.fieldNames;
|
|
450
|
+
});
|
|
451
|
+
const idColumns = pkFields.map(fieldName => this.#namingStrategy.joinKeyColumnName(prop.discriminator, fieldName, pkFields.length > 1));
|
|
452
|
+
prop.fieldNames = [prop.discriminatorColumn, ...idColumns];
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
else if ([ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind)) {
|
|
445
456
|
prop.fieldNames = this.initManyToOneFieldName(prop, prop.name);
|
|
446
457
|
}
|
|
447
458
|
else if (prop.kind === ReferenceKind.MANY_TO_MANY && prop.owner) {
|
|
@@ -1246,8 +1257,17 @@ export class MetadataDiscovery {
|
|
|
1246
1257
|
if (embeddedProp.nullable || refInArray) {
|
|
1247
1258
|
meta.properties[name].nullable = true;
|
|
1248
1259
|
}
|
|
1260
|
+
// polymorphic relations derive their column names from the discriminator, so prefix it too
|
|
1261
|
+
if (meta.properties[name].polymorphic && !object) {
|
|
1262
|
+
meta.properties[name].discriminator = prefix + meta.properties[name].discriminator;
|
|
1263
|
+
meta.properties[name].discriminatorColumn = prefix + meta.properties[name].discriminatorColumn;
|
|
1264
|
+
}
|
|
1249
1265
|
if (meta.properties[name].fieldNames) {
|
|
1250
|
-
|
|
1266
|
+
const { fieldNames, polymorphic } = meta.properties[name];
|
|
1267
|
+
// polymorphic `fieldNames` hold `[discriminatorColumn, ...fkIdColumns]`, so prefix all of them
|
|
1268
|
+
for (let i = 0; i < (polymorphic ? fieldNames.length : 1); i++) {
|
|
1269
|
+
fieldNames[i] = prefix + fieldNames[i];
|
|
1270
|
+
}
|
|
1251
1271
|
}
|
|
1252
1272
|
else {
|
|
1253
1273
|
const name2 = meta.properties[name].name;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "7.1.15-dev.
|
|
3
|
+
"version": "7.1.15-dev.8",
|
|
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",
|
|
@@ -587,7 +587,7 @@ export class EntityComparator {
|
|
|
587
587
|
}
|
|
588
588
|
}
|
|
589
589
|
else if (prop.polymorphic) {
|
|
590
|
-
const discriminatorMapKey = `discriminatorMapReverse_${prop.name}`;
|
|
590
|
+
const discriminatorMapKey = `discriminatorMapReverse_${this.safeKey(prop.name)}`;
|
|
591
591
|
const reverseMap = new Map();
|
|
592
592
|
for (const [key, value] of Object.entries(prop.discriminatorMap)) {
|
|
593
593
|
reverseMap.set(value, key);
|
package/utils/Utils.js
CHANGED
|
@@ -153,7 +153,7 @@ export function parseJsonSafe(value) {
|
|
|
153
153
|
/** Collection of general-purpose utility methods used throughout the ORM. */
|
|
154
154
|
export class Utils {
|
|
155
155
|
static PK_SEPARATOR = '~~~';
|
|
156
|
-
static #ORM_VERSION = '7.1.15-dev.
|
|
156
|
+
static #ORM_VERSION = '7.1.15-dev.8';
|
|
157
157
|
/**
|
|
158
158
|
* Checks if the argument is instance of `Object`. Returns false for arrays.
|
|
159
159
|
*/
|