@mikro-orm/core 7.0.7-dev.10 → 7.0.7-dev.11
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 +33 -2
- package/package.json +1 -1
- package/utils/Utils.js +1 -1
package/entity/EntityFactory.js
CHANGED
|
@@ -47,11 +47,32 @@ export class EntityFactory {
|
|
|
47
47
|
const exists = this.findEntity(data, meta2, options);
|
|
48
48
|
let wrapped = exists && helper(exists);
|
|
49
49
|
if (wrapped && !options.refresh) {
|
|
50
|
+
const wasInitialized = wrapped.isInitialized();
|
|
50
51
|
wrapped.__processing = true;
|
|
51
52
|
Utils.dropUndefinedProperties(data);
|
|
52
53
|
this.mergeData(meta2, exists, data, options);
|
|
53
54
|
wrapped.__processing = false;
|
|
55
|
+
wrapped.__initialized ||= !!options.initialized;
|
|
54
56
|
if (wrapped.isInitialized()) {
|
|
57
|
+
if (!wasInitialized) {
|
|
58
|
+
if (meta.root.inheritanceType && !(exists instanceof meta2.class)) {
|
|
59
|
+
Object.setPrototypeOf(exists, meta2.prototype);
|
|
60
|
+
}
|
|
61
|
+
if (options.merge && wrapped.hasPrimaryKey()) {
|
|
62
|
+
this.unitOfWork.register(exists, data, { loaded: options.initialized });
|
|
63
|
+
// ensure all data keys are tracked as loaded for shouldRefresh checks,
|
|
64
|
+
// but don't overwrite __originalEntityData — mergeData already set it
|
|
65
|
+
// with DB values for non-user-modified keys, leaving user changes detectable
|
|
66
|
+
for (const key of Utils.keys(data)) {
|
|
67
|
+
if (meta2.properties[key]) {
|
|
68
|
+
wrapped.__loadedProperties.add(key);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (this.#eventManager.hasListeners(EventType.onInit, meta2)) {
|
|
73
|
+
this.#eventManager.dispatchEvent(EventType.onInit, { entity: exists, meta: meta2, em: this.#em });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
55
76
|
return exists;
|
|
56
77
|
}
|
|
57
78
|
}
|
|
@@ -125,8 +146,18 @@ export class EntityFactory {
|
|
|
125
146
|
diff[meta.versionProperty] = data[meta.versionProperty];
|
|
126
147
|
}
|
|
127
148
|
const diff2 = this.#comparator.diffEntities(meta.class, existsData, data, { includeInverseSides: true });
|
|
128
|
-
// do not override values changed by user
|
|
129
|
-
|
|
149
|
+
// do not override values changed by user; for uninitialized entities,
|
|
150
|
+
// the diff may include stale snapshot entries (value is undefined) — skip those
|
|
151
|
+
if (helper(entity).__initialized) {
|
|
152
|
+
Utils.keys(diff).forEach(key => delete diff2[key]);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
Utils.keys(diff).forEach(key => {
|
|
156
|
+
if (diff[key] !== undefined) {
|
|
157
|
+
delete diff2[key];
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
130
161
|
Utils.keys(diff2)
|
|
131
162
|
.filter(key => {
|
|
132
163
|
// ignore null values if there is already present non-null value
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "7.0.7-dev.
|
|
3
|
+
"version": "7.0.7-dev.11",
|
|
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/Utils.js
CHANGED
|
@@ -132,7 +132,7 @@ export function parseJsonSafe(value) {
|
|
|
132
132
|
/** Collection of general-purpose utility methods used throughout the ORM. */
|
|
133
133
|
export class Utils {
|
|
134
134
|
static PK_SEPARATOR = '~~~';
|
|
135
|
-
static #ORM_VERSION = '7.0.7-dev.
|
|
135
|
+
static #ORM_VERSION = '7.0.7-dev.11';
|
|
136
136
|
/**
|
|
137
137
|
* Checks if the argument is instance of `Object`. Returns false for arrays.
|
|
138
138
|
*/
|