@mikro-orm/core 6.2.10-dev.59 → 6.2.10-dev.60
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
CHANGED
|
@@ -650,11 +650,6 @@ class EntityManager {
|
|
|
650
650
|
}
|
|
651
651
|
}
|
|
652
652
|
}
|
|
653
|
-
if (where == null) {
|
|
654
|
-
const compositeUniqueProps = meta.uniques.map(u => utils_1.Utils.asArray(u.properties).join(' + '));
|
|
655
|
-
const uniqueProps = meta.primaryKeys.concat(...unique).concat(compositeUniqueProps);
|
|
656
|
-
throw new Error(`Unique property value required for upsert, provide one of: ${uniqueProps.join(', ')}`);
|
|
657
|
-
}
|
|
658
653
|
data = utils_1.QueryHelper.processObjectParams(data);
|
|
659
654
|
em.validator.validateParams(data, 'insert data');
|
|
660
655
|
if (em.eventManager.hasListeners(enums_1.EventType.beforeUpsert, meta)) {
|
|
@@ -672,13 +667,20 @@ class EntityManager {
|
|
|
672
667
|
schema: options.schema,
|
|
673
668
|
convertCustomTypes: true,
|
|
674
669
|
});
|
|
675
|
-
em.unitOfWork.getChangeSetPersister().mapReturnedValues(entity, data, ret.row, meta);
|
|
670
|
+
em.unitOfWork.getChangeSetPersister().mapReturnedValues(entity, data, ret.row, meta, true);
|
|
676
671
|
const uniqueFields = options.onConflictFields ?? (utils_1.Utils.isPlainObject(where) ? Object.keys(where) : meta.primaryKeys);
|
|
677
672
|
const returning = (0, utils_1.getOnConflictReturningFields)(meta, data, uniqueFields, options);
|
|
678
673
|
if (options.onConflictAction === 'ignore' || !(0, entity_1.helper)(entity).hasPrimaryKey() || (returning.length > 0 && !(this.getPlatform().usesReturningStatement() && ret.row))) {
|
|
679
674
|
const where = {};
|
|
680
675
|
if (Array.isArray(uniqueFields)) {
|
|
681
|
-
|
|
676
|
+
for (const prop of uniqueFields) {
|
|
677
|
+
if (data[prop] != null) {
|
|
678
|
+
where[prop] = data[prop];
|
|
679
|
+
}
|
|
680
|
+
else if (meta.primaryKeys.includes(prop) && ret.insertId != null) {
|
|
681
|
+
where[prop] = ret.insertId;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
682
684
|
}
|
|
683
685
|
const data2 = await this.driver.findOne(meta.className, where, {
|
|
684
686
|
fields: returning,
|
|
@@ -793,11 +795,6 @@ class EntityManager {
|
|
|
793
795
|
}
|
|
794
796
|
}
|
|
795
797
|
}
|
|
796
|
-
if (where == null) {
|
|
797
|
-
const compositeUniqueProps = meta.uniques.map(u => utils_1.Utils.asArray(u.properties).join(' + '));
|
|
798
|
-
const uniqueProps = meta.primaryKeys.concat(...unique).concat(compositeUniqueProps);
|
|
799
|
-
throw new Error(`Unique property value required for upsert, provide one of: ${uniqueProps.join(', ')}`);
|
|
800
|
-
}
|
|
801
798
|
row = utils_1.QueryHelper.processObjectParams(row);
|
|
802
799
|
where = utils_1.QueryHelper.processWhere({
|
|
803
800
|
where,
|
|
@@ -834,7 +831,7 @@ class EntityManager {
|
|
|
834
831
|
schema: options.schema,
|
|
835
832
|
convertCustomTypes: true,
|
|
836
833
|
});
|
|
837
|
-
em.unitOfWork.getChangeSetPersister().mapReturnedValues(entity, utils_1.Utils.isEntity(data[i]) ? {} : data[i], res.rows?.[i], meta);
|
|
834
|
+
em.unitOfWork.getChangeSetPersister().mapReturnedValues(entity, utils_1.Utils.isEntity(data[i]) ? {} : data[i], res.rows?.[i], meta, true);
|
|
838
835
|
if (!(0, entity_1.helper)(entity).hasPrimaryKey()) {
|
|
839
836
|
loadPK.set(entity, allWhere[i]);
|
|
840
837
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "6.2.10-dev.
|
|
3
|
+
"version": "6.2.10-dev.60",
|
|
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.2.0",
|
|
66
66
|
"globby": "11.1.0",
|
|
67
|
-
"mikro-orm": "6.2.10-dev.
|
|
67
|
+
"mikro-orm": "6.2.10-dev.60",
|
|
68
68
|
"reflect-metadata": "0.2.2"
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -47,5 +47,5 @@ export declare class ChangeSetPersister {
|
|
|
47
47
|
* No need to handle composite keys here as they need to be set upfront.
|
|
48
48
|
* We do need to map to the change set payload too, as it will be used in the originalEntityData for new entities.
|
|
49
49
|
*/
|
|
50
|
-
mapReturnedValues<T extends object>(entity: T, payload: EntityDictionary<T>, row: Dictionary | undefined, meta: EntityMetadata<T
|
|
50
|
+
mapReturnedValues<T extends object>(entity: T, payload: EntityDictionary<T>, row: Dictionary | undefined, meta: EntityMetadata<T>, upsert?: boolean): void;
|
|
51
51
|
}
|
|
@@ -351,8 +351,8 @@ class ChangeSetPersister {
|
|
|
351
351
|
* No need to handle composite keys here as they need to be set upfront.
|
|
352
352
|
* We do need to map to the change set payload too, as it will be used in the originalEntityData for new entities.
|
|
353
353
|
*/
|
|
354
|
-
mapReturnedValues(entity, payload, row, meta) {
|
|
355
|
-
if (this.usesReturningStatement && row && utils_1.Utils.hasObjectKeys(row)) {
|
|
354
|
+
mapReturnedValues(entity, payload, row, meta, upsert = false) {
|
|
355
|
+
if ((this.usesReturningStatement || upsert) && row && utils_1.Utils.hasObjectKeys(row)) {
|
|
356
356
|
const mapped = this.comparator.mapResult(meta.className, row);
|
|
357
357
|
this.hydrator.hydrate(entity, meta, mapped, this.factory, 'full', false, true);
|
|
358
358
|
Object.assign(payload, mapped); // merge to the changeset payload, so it gets saved to the entity snapshot
|