@nocobase/database 1.4.0-alpha.8 → 1.4.0-beta.1
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/lib/collection.d.ts
CHANGED
|
@@ -95,6 +95,7 @@ export declare class Collection<TModelAttributes extends {} = any, TCreationAttr
|
|
|
95
95
|
findField(callback: (field: Field) => boolean): any;
|
|
96
96
|
hasField(name: string): boolean;
|
|
97
97
|
getField<F extends Field>(name: string): F;
|
|
98
|
+
getFieldByField(field: string): Field;
|
|
98
99
|
getFields(): any[];
|
|
99
100
|
addField(name: string, options: FieldOptions): Field;
|
|
100
101
|
checkFieldType(name: string, options: FieldOptions): void;
|
package/lib/collection.js
CHANGED
|
@@ -113,6 +113,9 @@ const _Collection = class _Collection extends import_events.EventEmitter {
|
|
|
113
113
|
var _a;
|
|
114
114
|
const targetKey = (_a = this.options) == null ? void 0 : _a.filterTargetKey;
|
|
115
115
|
if (Array.isArray(targetKey)) {
|
|
116
|
+
if (targetKey.length === 1) {
|
|
117
|
+
return targetKey[0];
|
|
118
|
+
}
|
|
116
119
|
return targetKey;
|
|
117
120
|
}
|
|
118
121
|
if (targetKey && this.model.getAttributes()[targetKey]) {
|
|
@@ -258,6 +261,9 @@ const _Collection = class _Collection extends import_events.EventEmitter {
|
|
|
258
261
|
getField(name) {
|
|
259
262
|
return this.fields.get(name);
|
|
260
263
|
}
|
|
264
|
+
getFieldByField(field) {
|
|
265
|
+
return this.findField((f) => f.options.field === field);
|
|
266
|
+
}
|
|
261
267
|
getFields() {
|
|
262
268
|
return [...this.fields.values()];
|
|
263
269
|
}
|
|
@@ -36,6 +36,7 @@ const _ToManyInterface = class _ToManyInterface extends import_base_interface.Ba
|
|
|
36
36
|
if (!str) {
|
|
37
37
|
return null;
|
|
38
38
|
}
|
|
39
|
+
str = `${str}`.trim();
|
|
39
40
|
const items = str.split(",");
|
|
40
41
|
const { filterKey, targetCollection, transaction } = ctx;
|
|
41
42
|
const targetInstances = await targetCollection.repository.find({
|
|
@@ -45,7 +46,7 @@ const _ToManyInterface = class _ToManyInterface extends import_base_interface.Ba
|
|
|
45
46
|
transaction
|
|
46
47
|
});
|
|
47
48
|
items.forEach((item) => {
|
|
48
|
-
if (!targetInstances.find((targetInstance) => targetInstance[filterKey]
|
|
49
|
+
if (!targetInstances.find((targetInstance) => targetInstance[filterKey] == item)) {
|
|
49
50
|
throw new Error(`"${item}" not found in ${targetCollection.model.name} ${filterKey}`);
|
|
50
51
|
}
|
|
51
52
|
});
|
|
@@ -99,13 +99,19 @@ const _MultipleRelationRepository = class _MultipleRelationRepository extends im
|
|
|
99
99
|
];
|
|
100
100
|
}
|
|
101
101
|
async count(options) {
|
|
102
|
+
var _a;
|
|
102
103
|
const transaction2 = await this.getTransaction(options);
|
|
103
104
|
const sourceModel = await this.getSourceModel(transaction2);
|
|
104
105
|
if (!sourceModel) return 0;
|
|
105
106
|
const queryOptions = this.buildQueryOptions(options);
|
|
107
|
+
const include = (_a = queryOptions.include) == null ? void 0 : _a.filter((item) => {
|
|
108
|
+
var _a2;
|
|
109
|
+
const association = (_a2 = this.targetModel.associations) == null ? void 0 : _a2[item.association];
|
|
110
|
+
return (association == null ? void 0 : association.associationType) !== "BelongsToArray";
|
|
111
|
+
});
|
|
106
112
|
const count = await sourceModel[this.accessors().get]({
|
|
107
113
|
where: queryOptions.where,
|
|
108
|
-
include
|
|
114
|
+
include,
|
|
109
115
|
includeIgnoreAttributes: false,
|
|
110
116
|
attributes: [
|
|
111
117
|
[
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/database",
|
|
3
|
-
"version": "1.4.0-
|
|
3
|
+
"version": "1.4.0-beta.1",
|
|
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": "1.4.0-
|
|
10
|
-
"@nocobase/utils": "1.4.0-
|
|
9
|
+
"@nocobase/logger": "1.4.0-beta.1",
|
|
10
|
+
"@nocobase/utils": "1.4.0-beta.1",
|
|
11
11
|
"async-mutex": "^0.3.2",
|
|
12
12
|
"chalk": "^4.1.1",
|
|
13
13
|
"cron-parser": "4.4.0",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
39
39
|
"directory": "packages/database"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "1ece4e558ba445088dbb658bd458eb0004295326"
|
|
42
42
|
}
|