@mikro-orm/core 7.0.12-dev.0 → 7.0.12-dev.10
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/EntityFactory.js +3 -1
- package/package.json +1 -1
- package/utils/QueryHelper.d.ts +5 -0
- package/utils/QueryHelper.js +24 -5
- package/utils/Utils.js +1 -1
package/entity/EntityFactory.js
CHANGED
|
@@ -305,7 +305,9 @@ export class EntityFactory {
|
|
|
305
305
|
/** @internal */
|
|
306
306
|
assignDefaultValues(entity, meta, onCreateOnly) {
|
|
307
307
|
for (const prop of meta.props) {
|
|
308
|
-
if (prop.embedded ||
|
|
308
|
+
if (prop.embedded ||
|
|
309
|
+
[ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind) ||
|
|
310
|
+
(prop.getter && !prop.setter)) {
|
|
309
311
|
continue;
|
|
310
312
|
}
|
|
311
313
|
if (prop.onCreate) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "7.0.12-dev.
|
|
3
|
+
"version": "7.0.12-dev.10",
|
|
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",
|
package/utils/QueryHelper.d.ts
CHANGED
|
@@ -38,6 +38,11 @@ export declare class QueryHelper {
|
|
|
38
38
|
* Handles shared FK columns (e.g., tenant_id referenced by multiple FKs) correctly.
|
|
39
39
|
*/
|
|
40
40
|
private static extractJoinColumnValues;
|
|
41
|
+
/**
|
|
42
|
+
* Expands a polymorphic entity reference to `[discriminatorValue, ...joinColumnValues]`,
|
|
43
|
+
* matching the column order of `prop.fieldNames`.
|
|
44
|
+
*/
|
|
45
|
+
private static extractPolymorphicJoinColumnValues;
|
|
41
46
|
/**
|
|
42
47
|
* Extracts the value for a specific column from an entity by finding which PK property
|
|
43
48
|
* owns that column and recursively traversing FK references.
|
package/utils/QueryHelper.js
CHANGED
|
@@ -327,18 +327,29 @@ export class QueryHelper {
|
|
|
327
327
|
continue;
|
|
328
328
|
}
|
|
329
329
|
const prop = meta.properties[k];
|
|
330
|
-
|
|
330
|
+
const polymorphic = !!prop?.polymorphic && (prop.fieldNames?.length ?? 0) > 1;
|
|
331
|
+
const composite = (prop?.joinColumns?.length ?? 0) > 1;
|
|
332
|
+
if (!polymorphic && !composite) {
|
|
331
333
|
continue;
|
|
332
334
|
}
|
|
335
|
+
const expand = (entity) => polymorphic
|
|
336
|
+
? this.extractPolymorphicJoinColumnValues(entity, prop)
|
|
337
|
+
: this.extractJoinColumnValues(entity, prop);
|
|
338
|
+
const expandItem = (item) => {
|
|
339
|
+
const entity = Reference.isReference(item) ? item.unwrap() : item;
|
|
340
|
+
return Utils.isEntity(entity) ? expand(entity) : item;
|
|
341
|
+
};
|
|
333
342
|
const w = where[k];
|
|
334
|
-
|
|
335
|
-
|
|
343
|
+
const expanded = expandItem(w);
|
|
344
|
+
if (expanded !== w) {
|
|
345
|
+
where[k] = expanded;
|
|
336
346
|
}
|
|
337
347
|
else if (Utils.isPlainObject(w)) {
|
|
338
348
|
for (const op of Object.keys(w)) {
|
|
339
|
-
if (Utils.isOperator(op, false)
|
|
340
|
-
|
|
349
|
+
if (!Utils.isOperator(op, false)) {
|
|
350
|
+
continue;
|
|
341
351
|
}
|
|
352
|
+
w[op] = Array.isArray(w[op]) ? w[op].map(expandItem) : expandItem(w[op]);
|
|
342
353
|
}
|
|
343
354
|
}
|
|
344
355
|
}
|
|
@@ -352,6 +363,14 @@ export class QueryHelper {
|
|
|
352
363
|
return this.extractColumnValue(entity, prop.targetMeta, refCol);
|
|
353
364
|
});
|
|
354
365
|
}
|
|
366
|
+
/**
|
|
367
|
+
* Expands a polymorphic entity reference to `[discriminatorValue, ...joinColumnValues]`,
|
|
368
|
+
* matching the column order of `prop.fieldNames`.
|
|
369
|
+
*/
|
|
370
|
+
static extractPolymorphicJoinColumnValues(entity, prop) {
|
|
371
|
+
const discriminator = this.findDiscriminatorValue(prop.discriminatorMap, entity.constructor);
|
|
372
|
+
return [discriminator, ...this.extractJoinColumnValues(entity, prop)];
|
|
373
|
+
}
|
|
355
374
|
/**
|
|
356
375
|
* Extracts the value for a specific column from an entity by finding which PK property
|
|
357
376
|
* owns that column and recursively traversing FK references.
|
package/utils/Utils.js
CHANGED
|
@@ -141,7 +141,7 @@ export function parseJsonSafe(value) {
|
|
|
141
141
|
/** Collection of general-purpose utility methods used throughout the ORM. */
|
|
142
142
|
export class Utils {
|
|
143
143
|
static PK_SEPARATOR = '~~~';
|
|
144
|
-
static #ORM_VERSION = '7.0.12-dev.
|
|
144
|
+
static #ORM_VERSION = '7.0.12-dev.10';
|
|
145
145
|
/**
|
|
146
146
|
* Checks if the argument is instance of `Object`. Returns false for arrays.
|
|
147
147
|
*/
|