metal-orm 1.1.20 → 1.1.21
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/dist/index.cjs +12 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -8
- package/dist/index.d.ts +7 -8
- package/dist/index.js +12 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/orm/relation-change-processor.ts +15 -11
package/dist/index.cjs
CHANGED
|
@@ -15070,7 +15070,10 @@ var RelationChangeProcessor = class {
|
|
|
15070
15070
|
const rootKey = relation.localKey || findPrimaryKey(entry.rootTable);
|
|
15071
15071
|
const rootId = entry.root[rootKey];
|
|
15072
15072
|
if (rootId === void 0 || rootId === null) return;
|
|
15073
|
-
const targetId = this.
|
|
15073
|
+
const targetId = this.resolveBelongsToManyTargetValue(
|
|
15074
|
+
entry.change.entity,
|
|
15075
|
+
relation
|
|
15076
|
+
);
|
|
15074
15077
|
if (targetId === null) return;
|
|
15075
15078
|
const pivotPayload = this.buildPivotPayload(relation, entry.change.pivot);
|
|
15076
15079
|
if (entry.change.kind === "update") {
|
|
@@ -15142,7 +15145,7 @@ var RelationChangeProcessor = class {
|
|
|
15142
15145
|
* Inserts a pivot row for belongs-to-many relations.
|
|
15143
15146
|
* @param relation - The belongs-to-many relation
|
|
15144
15147
|
* @param rootId - The root entity's primary key value
|
|
15145
|
-
* @param targetId - The target entity's
|
|
15148
|
+
* @param targetId - The target entity's relation key value
|
|
15146
15149
|
*/
|
|
15147
15150
|
async insertPivotRow(relation, rootId, targetId, pivotPayload) {
|
|
15148
15151
|
const payload = {
|
|
@@ -15158,7 +15161,7 @@ var RelationChangeProcessor = class {
|
|
|
15158
15161
|
* Updates a pivot row for belongs-to-many relations.
|
|
15159
15162
|
* @param relation - The belongs-to-many relation
|
|
15160
15163
|
* @param rootId - The root entity's primary key value
|
|
15161
|
-
* @param targetId - The target entity's
|
|
15164
|
+
* @param targetId - The target entity's relation key value
|
|
15162
15165
|
* @param pivotPayload - The pivot columns to update
|
|
15163
15166
|
*/
|
|
15164
15167
|
async updatePivotRow(relation, rootId, targetId, pivotPayload) {
|
|
@@ -15173,7 +15176,7 @@ var RelationChangeProcessor = class {
|
|
|
15173
15176
|
* Deletes a pivot row for belongs-to-many relations.
|
|
15174
15177
|
* @param relation - The belongs-to-many relation
|
|
15175
15178
|
* @param rootId - The root entity's primary key value
|
|
15176
|
-
* @param targetId - The target entity's
|
|
15179
|
+
* @param targetId - The target entity's relation key value
|
|
15177
15180
|
*/
|
|
15178
15181
|
async deletePivotRow(relation, rootId, targetId) {
|
|
15179
15182
|
const rootCol = relation.pivotTable.columns[relation.pivotForeignKeyToRoot];
|
|
@@ -15186,14 +15189,13 @@ var RelationChangeProcessor = class {
|
|
|
15186
15189
|
await this.executor.executeSql(compiled.sql, compiled.params);
|
|
15187
15190
|
}
|
|
15188
15191
|
/**
|
|
15189
|
-
* Resolves the
|
|
15190
|
-
*
|
|
15191
|
-
*
|
|
15192
|
-
* @returns The primary key value or null
|
|
15192
|
+
* Resolves the target-side key value used by a belongs-to-many relation.
|
|
15193
|
+
* The declared targetKey is part of the relation contract and takes
|
|
15194
|
+
* precedence over the target table primary key.
|
|
15193
15195
|
*/
|
|
15194
|
-
|
|
15196
|
+
resolveBelongsToManyTargetValue(entity, relation) {
|
|
15195
15197
|
if (!entity) return null;
|
|
15196
|
-
const key = findPrimaryKey(
|
|
15198
|
+
const key = relation.targetKey || findPrimaryKey(relation.target);
|
|
15197
15199
|
const value = entity[key];
|
|
15198
15200
|
if (value === void 0 || value === null) return null;
|
|
15199
15201
|
return value ?? null;
|