@nocobase/plugin-field-m2m-array 2.0.0-alpha.9 → 2.0.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/dist/externalVersion.js +6 -5
- package/dist/locale/de-DE.json +1 -1
- package/dist/locale/en-US.json +1 -1
- package/dist/locale/es-ES.json +4 -0
- package/dist/locale/fr-FR.json +4 -0
- package/dist/locale/hu-HU.json +4 -0
- package/dist/locale/id-ID.json +4 -0
- package/dist/locale/it-IT.json +1 -1
- package/dist/locale/ko-KR.json +4 -0
- package/dist/locale/nl-NL.json +2 -2
- package/dist/locale/pt-BR.json +4 -0
- package/dist/locale/ru-RU.json +4 -0
- package/dist/locale/tr-TR.json +4 -0
- package/dist/locale/uk-UA.json +4 -0
- package/dist/locale/vi-VN.json +4 -0
- package/dist/locale/zh-CN.json +1 -1
- package/dist/locale/zh-TW.json +4 -0
- package/dist/server/belongs-to-array-field.d.ts +1 -0
- package/dist/server/belongs-to-array-field.js +36 -8
- package/package.json +4 -2
package/dist/externalVersion.js
CHANGED
|
@@ -11,10 +11,11 @@ module.exports = {
|
|
|
11
11
|
"@formily/react": "2.3.7",
|
|
12
12
|
"antd": "5.24.2",
|
|
13
13
|
"react": "18.2.0",
|
|
14
|
-
"@nocobase/client": "2.0.0-
|
|
14
|
+
"@nocobase/client": "2.0.0-beta.1",
|
|
15
15
|
"react-router-dom": "6.30.1",
|
|
16
|
-
"@nocobase/utils": "2.0.0-
|
|
17
|
-
"@nocobase/database": "2.0.0-
|
|
18
|
-
"
|
|
19
|
-
"@nocobase/
|
|
16
|
+
"@nocobase/utils": "2.0.0-beta.1",
|
|
17
|
+
"@nocobase/database": "2.0.0-beta.1",
|
|
18
|
+
"lodash": "4.17.21",
|
|
19
|
+
"@nocobase/server": "2.0.0-beta.1",
|
|
20
|
+
"@nocobase/data-source-manager": "2.0.0-beta.1"
|
|
20
21
|
};
|
package/dist/locale/de-DE.json
CHANGED
package/dist/locale/en-US.json
CHANGED
package/dist/locale/it-IT.json
CHANGED
package/dist/locale/nl-NL.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
"Many to many (array)": "Veel-op-veel (array)",
|
|
3
|
+
"Many to many (array) description": "Hiermee kan je veel-op-veel-relaties tussen twee modellen maken door een array met unieke sleutels van het doelmodel op te slaan."
|
|
4
4
|
}
|
package/dist/locale/zh-CN.json
CHANGED
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
var __create = Object.create;
|
|
10
11
|
var __defProp = Object.defineProperty;
|
|
11
12
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
13
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
13
15
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
16
|
var __export = (target, all) => {
|
|
15
17
|
for (var name in all)
|
|
@@ -23,6 +25,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
23
25
|
}
|
|
24
26
|
return to;
|
|
25
27
|
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
+
mod
|
|
35
|
+
));
|
|
26
36
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
37
|
var belongs_to_array_field_exports = {};
|
|
28
38
|
__export(belongs_to_array_field_exports, {
|
|
@@ -31,23 +41,32 @@ __export(belongs_to_array_field_exports, {
|
|
|
31
41
|
});
|
|
32
42
|
module.exports = __toCommonJS(belongs_to_array_field_exports);
|
|
33
43
|
var import_database = require("@nocobase/database");
|
|
44
|
+
var import_lodash = __toESM(require("lodash"));
|
|
34
45
|
const elementTypeMap = {
|
|
35
46
|
nanoid: "string",
|
|
36
47
|
sequence: "string",
|
|
37
|
-
uid: "string"
|
|
48
|
+
uid: "string",
|
|
49
|
+
snowflakeId: "bigInt"
|
|
38
50
|
};
|
|
39
51
|
class BelongsToArrayField extends import_database.RelationField {
|
|
40
52
|
get dataType() {
|
|
41
53
|
return "BelongsToArray";
|
|
42
54
|
}
|
|
43
|
-
setForeignKeyArray = async (model, { values, transaction }) => {
|
|
44
|
-
const { name, foreignKey, target, targetKey } = this.options;
|
|
45
|
-
if (
|
|
55
|
+
setForeignKeyArray = async (model, { values, transaction, inputValues }) => {
|
|
56
|
+
const { type, name, foreignKey, target, targetKey } = this.options;
|
|
57
|
+
if (type !== "belongsToArray") {
|
|
46
58
|
return;
|
|
47
59
|
}
|
|
48
|
-
let value
|
|
49
|
-
|
|
50
|
-
|
|
60
|
+
let value;
|
|
61
|
+
const valuesInParams = (inputValues ?? values ?? {})[name];
|
|
62
|
+
if (valuesInParams !== void 0) {
|
|
63
|
+
value = import_lodash.default.castArray(valuesInParams || []);
|
|
64
|
+
} else {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (value.length === 0) {
|
|
68
|
+
model.set(foreignKey, []);
|
|
69
|
+
return;
|
|
51
70
|
}
|
|
52
71
|
const tks = [];
|
|
53
72
|
const items = [];
|
|
@@ -67,10 +86,19 @@ class BelongsToArrayField extends import_database.RelationField {
|
|
|
67
86
|
transaction
|
|
68
87
|
});
|
|
69
88
|
tks.push(...instances.map((instance) => instance[targetKey]));
|
|
70
|
-
const toCreate = items.filter((item) => !item[targetKey] || !tks.includes(item[targetKey]));
|
|
71
89
|
const m = this.database.getModel(target);
|
|
90
|
+
const toCreate = items.filter((item) => !item[targetKey] || !tks.includes(item[targetKey]));
|
|
72
91
|
const newInstances = await m.bulkCreate(toCreate, { transaction });
|
|
73
92
|
tks.push(...newInstances.map((instance) => instance[targetKey]));
|
|
93
|
+
const toUpdate = items.filter((item) => item[targetKey] && tks.includes(item[targetKey]));
|
|
94
|
+
for (const item of toUpdate) {
|
|
95
|
+
await m.update(item, {
|
|
96
|
+
where: {
|
|
97
|
+
[targetKey]: item[targetKey]
|
|
98
|
+
},
|
|
99
|
+
transaction
|
|
100
|
+
});
|
|
101
|
+
}
|
|
74
102
|
model.set(foreignKey, tks);
|
|
75
103
|
};
|
|
76
104
|
checkTargetCollection() {
|
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-field-m2m-array",
|
|
3
3
|
"displayName": "Collection field: Many to many (array)",
|
|
4
|
+
"displayName.ru-RU": "Связь коллекций: «многие ко многим» (массив)",
|
|
4
5
|
"displayName.zh-CN": "数据表字段:多对多 (数组)",
|
|
5
6
|
"description": "Allows to create many to many relationships between two models by storing an array of unique keys of the target model.",
|
|
7
|
+
"description.ru-RU": "Позволяет создавать отношения «многие ко многим» между двумя моделями, сохраняя массив уникальных ключей целевой модели.",
|
|
6
8
|
"description.zh-CN": "支持通过在数组中存储目标表唯一键的方式建立多对多关系。",
|
|
7
|
-
"version": "2.0.0-
|
|
9
|
+
"version": "2.0.0-beta.1",
|
|
8
10
|
"main": "dist/server/index.js",
|
|
9
11
|
"peerDependencies": {
|
|
10
12
|
"@nocobase/client": "2.x",
|
|
@@ -14,5 +16,5 @@
|
|
|
14
16
|
"keywords": [
|
|
15
17
|
"Collection fields"
|
|
16
18
|
],
|
|
17
|
-
"gitHead": "
|
|
19
|
+
"gitHead": "b3d1f65848fc91e673372ee734dafe6b1cf80586"
|
|
18
20
|
}
|