@mikro-orm/core 6.5.7-dev.21 → 6.5.7-dev.23
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/EntityManager.d.ts +1 -0
- package/EntityManager.js +3 -1
- package/package.json +2 -2
- package/utils/TransactionManager.js +16 -4
package/EntityManager.d.ts
CHANGED
|
@@ -580,6 +580,7 @@ export interface MergeOptions {
|
|
|
580
580
|
disableContextResolution?: boolean;
|
|
581
581
|
keepIdentity?: boolean;
|
|
582
582
|
validate?: boolean;
|
|
583
|
+
cascade?: boolean; /** @default true */
|
|
583
584
|
}
|
|
584
585
|
export interface ForkOptions {
|
|
585
586
|
/** do we want a clear identity map? defaults to true */
|
package/EntityManager.js
CHANGED
|
@@ -1187,6 +1187,7 @@ class EntityManager {
|
|
|
1187
1187
|
const em = options.disableContextResolution ? this : this.getContext();
|
|
1188
1188
|
options.schema ??= em._schema;
|
|
1189
1189
|
options.validate ??= true;
|
|
1190
|
+
options.cascade ??= true;
|
|
1190
1191
|
entityName = utils_1.Utils.className(entityName);
|
|
1191
1192
|
if (options.validate) {
|
|
1192
1193
|
em.validator.validatePrimaryKey(data, em.metadata.get(entityName));
|
|
@@ -1207,7 +1208,8 @@ class EntityManager {
|
|
|
1207
1208
|
if (options.validate) {
|
|
1208
1209
|
em.validator.validate(entity, data, childMeta ?? meta);
|
|
1209
1210
|
}
|
|
1210
|
-
|
|
1211
|
+
const visited = options.cascade ? undefined : new Set([entity]);
|
|
1212
|
+
em.unitOfWork.merge(entity, visited);
|
|
1211
1213
|
return entity;
|
|
1212
1214
|
}
|
|
1213
1215
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "6.5.7-dev.
|
|
3
|
+
"version": "6.5.7-dev.23",
|
|
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
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"esprima": "4.0.1",
|
|
65
65
|
"fs-extra": "11.3.2",
|
|
66
66
|
"globby": "11.1.0",
|
|
67
|
-
"mikro-orm": "6.5.7-dev.
|
|
67
|
+
"mikro-orm": "6.5.7-dev.23",
|
|
68
68
|
"reflect-metadata": "0.2.2"
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -153,16 +153,28 @@ class TransactionManager {
|
|
|
153
153
|
* Merges entities from fork to parent EntityManager.
|
|
154
154
|
*/
|
|
155
155
|
mergeEntitiesToParent(fork, parent) {
|
|
156
|
-
|
|
157
|
-
if
|
|
156
|
+
const parentUoW = parent.getUnitOfWork(false);
|
|
157
|
+
// perf: if parent is empty, we can just move all entities from the fork to skip the `em.merge` overhead
|
|
158
|
+
if (parentUoW.getIdentityMap().keys().length === 0) {
|
|
158
159
|
for (const entity of fork.getUnitOfWork(false).getIdentityMap()) {
|
|
159
|
-
|
|
160
|
+
parentUoW.getIdentityMap().store(entity);
|
|
160
161
|
(0, wrap_1.helper)(entity).__em = parent;
|
|
161
162
|
}
|
|
162
163
|
return;
|
|
163
164
|
}
|
|
164
165
|
for (const entity of fork.getUnitOfWork(false).getIdentityMap()) {
|
|
165
|
-
|
|
166
|
+
const wrapped = (0, wrap_1.helper)(entity);
|
|
167
|
+
const meta = wrapped.__meta;
|
|
168
|
+
// eslint-disable-next-line dot-notation
|
|
169
|
+
const parentEntity = parentUoW.getById(meta.className, wrapped.getPrimaryKey(), parent['_schema'], true);
|
|
170
|
+
if (parentEntity && parentEntity !== entity) {
|
|
171
|
+
const parentWrapped = (0, wrap_1.helper)(parentEntity);
|
|
172
|
+
parentWrapped.__data = (0, wrap_1.helper)(entity).__data;
|
|
173
|
+
parentWrapped.__originalEntityData = (0, wrap_1.helper)(entity).__originalEntityData;
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
parentUoW.merge(entity, new Set([entity]));
|
|
177
|
+
}
|
|
166
178
|
}
|
|
167
179
|
}
|
|
168
180
|
/**
|