@mikro-orm/core 7.2.12-dev.15 → 7.2.12-dev.16
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.d.ts +2 -0
- package/entity/EntityFactory.js +24 -0
- package/package.json +1 -1
- package/utils/Utils.js +1 -1
|
@@ -45,6 +45,8 @@ export declare class EntityFactory {
|
|
|
45
45
|
private isNoopMerge;
|
|
46
46
|
/** Whether hydrating `value` into `prop` would leave `current` as is, mirroring the hydrator's Date and boolean coercion. */
|
|
47
47
|
private holdsValue;
|
|
48
|
+
/** Whether the owning side of an inverse 1:1 `prop` carries an unflushed change on the given target. */
|
|
49
|
+
private hasPendingOwner;
|
|
48
50
|
/** Merges new data into an existing entity, preserving user-modified properties. */
|
|
49
51
|
mergeData<T extends object>(meta: EntityMetadata<T>, entity: T, data: EntityData<T>, options?: FactoryOptions): void;
|
|
50
52
|
/** Creates or retrieves an uninitialized entity reference by its primary key or alternate key. */
|
package/entity/EntityFactory.js
CHANGED
|
@@ -186,6 +186,18 @@ export class EntityFactory {
|
|
|
186
186
|
}
|
|
187
187
|
return current === value;
|
|
188
188
|
}
|
|
189
|
+
/** Whether the owning side of an inverse 1:1 `prop` carries an unflushed change on the given target. */
|
|
190
|
+
hasPendingOwner(target, prop) {
|
|
191
|
+
// a reference gets its owning side set during hydration, that is not a change
|
|
192
|
+
if (!target || !helper(target).__initialized) {
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
const owner = target[prop.mappedBy];
|
|
196
|
+
const fk = Utils.isEntity(owner, true)
|
|
197
|
+
? Utils.getPrimaryKeyValues(Reference.unwrapReference(owner), prop.targetMeta.properties[prop.mappedBy].targetMeta, true, true)
|
|
198
|
+
: owner;
|
|
199
|
+
return !Utils.equals(fk ?? null, helper(target).__originalEntityData?.[prop.mappedBy] ?? null);
|
|
200
|
+
}
|
|
189
201
|
/** Merges new data into an existing entity, preserving user-modified properties. */
|
|
190
202
|
mergeData(meta, entity, data, options = {}) {
|
|
191
203
|
// joined rows often repeat exactly what the entity already holds, skip the snapshot and diffing then
|
|
@@ -210,6 +222,18 @@ export class EntityFactory {
|
|
|
210
222
|
}
|
|
211
223
|
});
|
|
212
224
|
}
|
|
225
|
+
// inverse 1:1 sides are not snapshotted, their pending changes are visible only on the owning side
|
|
226
|
+
Utils.keys(diff2)
|
|
227
|
+
.filter(key => meta.properties[key].kind === ReferenceKind.ONE_TO_ONE && !meta.properties[key].owner)
|
|
228
|
+
.filter(key => {
|
|
229
|
+
const prop = meta.properties[key];
|
|
230
|
+
const current = entity[key] ? Reference.unwrapReference(entity[key]) : undefined;
|
|
231
|
+
const loaded = Utils.isPlainObject(diff2[key])
|
|
232
|
+
? this.findEntity(diff2[key], prop.targetMeta, options)
|
|
233
|
+
: undefined;
|
|
234
|
+
return this.hasPendingOwner(current, prop) || (loaded !== current && this.hasPendingOwner(loaded, prop));
|
|
235
|
+
})
|
|
236
|
+
.forEach(key => delete diff2[key]);
|
|
213
237
|
Utils.keys(diff2)
|
|
214
238
|
.filter(key => {
|
|
215
239
|
// 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.2.12-dev.
|
|
3
|
+
"version": "7.2.12-dev.16",
|
|
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
|
@@ -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.2.12-dev.
|
|
156
|
+
static #ORM_VERSION = '7.2.12-dev.16';
|
|
157
157
|
/** Default session variable name backing an RLS filter argument (`current_setting('mikro.<filter>.<arg>')`). */
|
|
158
158
|
static getRlsSettingName(filterName, argName) {
|
|
159
159
|
return `mikro.${filterName}.${argName}`;
|