@nocobase/database 2.0.0-alpha.42 → 2.0.0-alpha.44
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.
|
@@ -12,7 +12,6 @@ import { FindOptions } from '../repository';
|
|
|
12
12
|
import { MultipleRelationRepository } from '../relation-repository/multiple-relation-repository';
|
|
13
13
|
import Database from '../database';
|
|
14
14
|
import { Model } from '../model';
|
|
15
|
-
import { UpdateAssociationOptions } from '../update-associations';
|
|
16
15
|
export declare class BelongsToArrayAssociation {
|
|
17
16
|
db: Database;
|
|
18
17
|
associationType: string;
|
|
@@ -35,7 +34,6 @@ export declare class BelongsToArrayAssociation {
|
|
|
35
34
|
generateInclude(parentAs?: string): {
|
|
36
35
|
on: void;
|
|
37
36
|
};
|
|
38
|
-
update(instance: Model, value: any, options?: UpdateAssociationOptions): Promise<void>;
|
|
39
37
|
}
|
|
40
38
|
export declare class BelongsToArrayRepository extends MultipleRelationRepository {
|
|
41
39
|
private belongsToArrayAssociation;
|
|
@@ -94,19 +94,6 @@ const _BelongsToArrayAssociation = class _BelongsToArrayAssociation {
|
|
|
94
94
|
on: this.db.queryInterface.generateJoinOnForJSONArray(left, right)
|
|
95
95
|
};
|
|
96
96
|
}
|
|
97
|
-
async update(instance, value, options = {}) {
|
|
98
|
-
await instance.update(
|
|
99
|
-
{
|
|
100
|
-
[this.as]: value
|
|
101
|
-
},
|
|
102
|
-
{
|
|
103
|
-
values: {
|
|
104
|
-
[this.as]: value
|
|
105
|
-
},
|
|
106
|
-
transaction: options == null ? void 0 : options.transaction
|
|
107
|
-
}
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
97
|
};
|
|
111
98
|
__name(_BelongsToArrayAssociation, "BelongsToArrayAssociation");
|
|
112
99
|
let BelongsToArrayAssociation = _BelongsToArrayAssociation;
|
|
@@ -13,9 +13,7 @@ export declare function modelAssociations(instance: Model): {
|
|
|
13
13
|
[key: string]: Association<import("sequelize").Model<any, any>, import("sequelize").Model<any, any>>;
|
|
14
14
|
};
|
|
15
15
|
export declare function belongsToManyAssociations(instance: Model): Array<BelongsToMany>;
|
|
16
|
-
export declare function modelAssociationByKey(instance: Model, key: string): Association
|
|
17
|
-
update?: (instance: Model, value: any, options: UpdateAssociationOptions) => Promise<any>;
|
|
18
|
-
};
|
|
16
|
+
export declare function modelAssociationByKey(instance: Model, key: string): Association;
|
|
19
17
|
type UpdateValue = {
|
|
20
18
|
[key: string]: any;
|
|
21
19
|
};
|
|
@@ -51,7 +49,7 @@ export declare function updateAssociations(instance: Model, values: any, options
|
|
|
51
49
|
* @param value
|
|
52
50
|
* @param options
|
|
53
51
|
*/
|
|
54
|
-
export declare function updateAssociation(instance: Model, key: string, value: any, options?: UpdateAssociationOptions): Promise<
|
|
52
|
+
export declare function updateAssociation(instance: Model, key: string, value: any, options?: UpdateAssociationOptions): Promise<boolean>;
|
|
55
53
|
/**
|
|
56
54
|
* update belongsTo and HasOne
|
|
57
55
|
* @param model
|
|
@@ -176,9 +176,6 @@ async function updateAssociation(instance, key, value, options = {}) {
|
|
|
176
176
|
if (options.associationContext && isReverseAssociationPair(association, options.associationContext)) {
|
|
177
177
|
return false;
|
|
178
178
|
}
|
|
179
|
-
if (association.update) {
|
|
180
|
-
return association.update(instance, value, options);
|
|
181
|
-
}
|
|
182
179
|
switch (association.associationType) {
|
|
183
180
|
case "HasOne":
|
|
184
181
|
case "BelongsTo":
|
|
@@ -223,11 +220,11 @@ async function updateSingleAssociation(model, key, value, options = {}) {
|
|
|
223
220
|
}
|
|
224
221
|
}, "checkBelongsToForeignKeyValue");
|
|
225
222
|
if ((0, import_utils.isStringOrNumber)(value)) {
|
|
226
|
-
await model[setAccessor](value, { context, transaction });
|
|
223
|
+
await model[setAccessor](value, { context, transaction, associationKey: key });
|
|
227
224
|
return true;
|
|
228
225
|
}
|
|
229
226
|
if (value instanceof import_model.Model) {
|
|
230
|
-
await model[setAccessor](value, { context, transaction });
|
|
227
|
+
await model[setAccessor](value, { context, transaction, associationKey: key });
|
|
231
228
|
model.setDataValue(key, value);
|
|
232
229
|
return true;
|
|
233
230
|
}
|
|
@@ -258,7 +255,7 @@ async function updateSingleAssociation(model, key, value, options = {}) {
|
|
|
258
255
|
if (association.associationType === "HasOne") {
|
|
259
256
|
delete updateValues[association.foreignKey];
|
|
260
257
|
}
|
|
261
|
-
await instance2.update(updateValues, { ...options, transaction });
|
|
258
|
+
await instance2.update(updateValues, { ...options, transaction, associationKey: key });
|
|
262
259
|
}
|
|
263
260
|
await updateAssociations(instance2, value, {
|
|
264
261
|
...options,
|
|
@@ -274,7 +271,7 @@ async function updateSingleAssociation(model, key, value, options = {}) {
|
|
|
274
271
|
values: value,
|
|
275
272
|
operation: "create"
|
|
276
273
|
});
|
|
277
|
-
const instance = await model[createAccessor](value, { context, transaction });
|
|
274
|
+
const instance = await model[createAccessor](value, { context, transaction, associationKey: key });
|
|
278
275
|
await updateAssociations(instance, value, {
|
|
279
276
|
...options,
|
|
280
277
|
transaction,
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/database",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.44",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
7
|
"license": "AGPL-3.0",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@nocobase/logger": "2.0.0-alpha.
|
|
10
|
-
"@nocobase/utils": "2.0.0-alpha.
|
|
9
|
+
"@nocobase/logger": "2.0.0-alpha.44",
|
|
10
|
+
"@nocobase/utils": "2.0.0-alpha.44",
|
|
11
11
|
"async-mutex": "^0.3.2",
|
|
12
12
|
"chalk": "^4.1.1",
|
|
13
13
|
"cron-parser": "4.4.0",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
40
40
|
"directory": "packages/database"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "075bd484c270740fe9b02f1989818da91139b6b9"
|
|
43
43
|
}
|