@mikro-orm/core 7.0.6-dev.8 → 7.0.6-dev.9
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.js +4 -0
- package/entity/EntityFactory.d.ts +2 -1
- package/entity/EntityFactory.js +4 -3
- package/package.json +1 -1
- package/utils/Utils.js +1 -1
package/EntityManager.js
CHANGED
|
@@ -779,6 +779,7 @@ export class EntityManager {
|
|
|
779
779
|
return entity;
|
|
780
780
|
}
|
|
781
781
|
where = helper(entity).getPrimaryKey();
|
|
782
|
+
em.#entityFactory.assignDefaultValues(entity, meta);
|
|
782
783
|
data = em.#comparator.prepareEntity(entity);
|
|
783
784
|
}
|
|
784
785
|
else {
|
|
@@ -790,6 +791,7 @@ export class EntityManager {
|
|
|
790
791
|
return em.assign(exists, data);
|
|
791
792
|
}
|
|
792
793
|
}
|
|
794
|
+
em.#entityFactory.assignDefaultValues(data, meta, true);
|
|
793
795
|
for (const key of Object.keys(data)) {
|
|
794
796
|
const prop = meta.properties[key];
|
|
795
797
|
if (prop?.persist === false) {
|
|
@@ -928,6 +930,7 @@ export class EntityManager {
|
|
|
928
930
|
continue;
|
|
929
931
|
}
|
|
930
932
|
where = helper(entity).getPrimaryKey();
|
|
933
|
+
em.#entityFactory.assignDefaultValues(entity, meta);
|
|
931
934
|
row = em.#comparator.prepareEntity(entity);
|
|
932
935
|
}
|
|
933
936
|
else {
|
|
@@ -942,6 +945,7 @@ export class EntityManager {
|
|
|
942
945
|
continue;
|
|
943
946
|
}
|
|
944
947
|
}
|
|
948
|
+
em.#entityFactory.assignDefaultValues(row, meta, true);
|
|
945
949
|
for (const key of Object.keys(row)) {
|
|
946
950
|
const prop = meta.properties[key];
|
|
947
951
|
if (prop?.persist === false) {
|
|
@@ -47,7 +47,8 @@ export declare class EntityFactory {
|
|
|
47
47
|
/** Returns the EntityComparator instance used for diffing entities. */
|
|
48
48
|
getComparator(): EntityComparator;
|
|
49
49
|
private createEntity;
|
|
50
|
-
|
|
50
|
+
/** @internal */
|
|
51
|
+
assignDefaultValues<T extends object>(entity: T, meta: EntityMetadata<T>, onCreateOnly?: boolean): void;
|
|
51
52
|
private hydrate;
|
|
52
53
|
private findEntity;
|
|
53
54
|
private processDiscriminatorColumn;
|
package/entity/EntityFactory.js
CHANGED
|
@@ -274,7 +274,8 @@ export class EntityFactory {
|
|
|
274
274
|
}
|
|
275
275
|
return entity;
|
|
276
276
|
}
|
|
277
|
-
|
|
277
|
+
/** @internal */
|
|
278
|
+
assignDefaultValues(entity, meta, onCreateOnly) {
|
|
278
279
|
for (const prop of meta.props) {
|
|
279
280
|
if (prop.embedded || [ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind)) {
|
|
280
281
|
continue;
|
|
@@ -282,13 +283,13 @@ export class EntityFactory {
|
|
|
282
283
|
if (prop.onCreate) {
|
|
283
284
|
entity[prop.name] ??= prop.onCreate(entity, this.#em);
|
|
284
285
|
}
|
|
285
|
-
else if (prop.default != null && !isRaw(prop.default) && entity[prop.name] === undefined) {
|
|
286
|
+
else if (!onCreateOnly && prop.default != null && !isRaw(prop.default) && entity[prop.name] === undefined) {
|
|
286
287
|
entity[prop.name] = prop.default;
|
|
287
288
|
}
|
|
288
289
|
if (prop.kind === ReferenceKind.EMBEDDED && entity[prop.name]) {
|
|
289
290
|
const items = prop.array ? entity[prop.name] : [entity[prop.name]];
|
|
290
291
|
for (const item of items) {
|
|
291
|
-
this.assignDefaultValues(item, prop.targetMeta);
|
|
292
|
+
this.assignDefaultValues(item, prop.targetMeta, onCreateOnly);
|
|
292
293
|
}
|
|
293
294
|
}
|
|
294
295
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "7.0.6-dev.
|
|
3
|
+
"version": "7.0.6-dev.9",
|
|
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.6-dev.
|
|
135
|
+
static #ORM_VERSION = '7.0.6-dev.9';
|
|
136
136
|
/**
|
|
137
137
|
* Checks if the argument is instance of `Object`. Returns false for arrays.
|
|
138
138
|
*/
|