@nocobase/plugin-field-m2m-array 2.0.0-alpha.9 → 2.1.0-alpha.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.
@@ -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-alpha.9",
14
+ "@nocobase/client": "2.1.0-alpha.1",
15
15
  "react-router-dom": "6.30.1",
16
- "@nocobase/utils": "2.0.0-alpha.9",
17
- "@nocobase/database": "2.0.0-alpha.9",
18
- "@nocobase/server": "2.0.0-alpha.9",
19
- "@nocobase/data-source-manager": "2.0.0-alpha.9"
16
+ "@nocobase/utils": "2.1.0-alpha.1",
17
+ "@nocobase/database": "2.1.0-alpha.1",
18
+ "lodash": "4.17.21",
19
+ "@nocobase/server": "2.1.0-alpha.1",
20
+ "@nocobase/data-source-manager": "2.1.0-alpha.1"
20
21
  };
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "Many to many (array)": "Viele-zu-viele (Array)",
3
3
  "Many to many (array) description": "Ermöglicht die Erstellung von Viele-zu-viele-Beziehungen zwischen zwei Modellen durch Speicherung eines Arrays eindeutiger Schlüssel des Zielmodells."
4
- }
4
+ }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "Many to many (array)": "Many to many (array)",
3
3
  "Many to many (array) description": "Allows to create many to many relationships between two models by storing an array of unique keys of the target model."
4
- }
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "Many to many (array)": "Many to many (array)",
3
+ "Many to many (array) description": "Allows to create many to many relationships between two models by storing an array of unique keys of the target model."
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "Many to many (array)": "Many to many (array)",
3
+ "Many to many (array) description": "Allows to create many to many relationships between two models by storing an array of unique keys of the target model."
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "Many to many (array)": "Több a többhöz (tömb)",
3
+ "Many to many (array) description": "Lehetővé teszi több a többhöz kapcsolatok létrehozását két modell között a cél modell egyedi kulcsainak tárolásával tömbben."
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "Many to many (array)": "Banyak ke banyak (array)",
3
+ "Many to many (array) description": "Memungkinkan untuk membuat hubungan banyak ke banyak antara dua model dengan menyimpan array kunci unik dari model target."
4
+ }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "Many to many (array)": "Molti a molti (array)",
3
3
  "Many to many (array) description": "Consente di creare relazioni molti a molti tra due modelli memorizzando un array di chiavi univoche del modello di destinazione."
4
- }
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "Many to many (array)": "다 대 다(배열)",
3
+ "Many to many (array) description": "대상 모델의 고유 키 배열을 저장하여 두 모델 간의 다대다 관계를 생성할 수 있습니다."
4
+ }
@@ -1,4 +1,4 @@
1
1
  {
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."
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
  }
@@ -0,0 +1,4 @@
1
+ {
2
+ "Many to many (array)": "Many to many (array)",
3
+ "Many to many (array) description": "Allows to create many to many relationships between two models by storing an array of unique keys of the target model."
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "Many to many (array)": "Многие ко многим (Many to many (array))",
3
+ "Many to many (array) description": "Позволяет создавать отношения многие-ко-многим между двумя моделями, сохраняя массив (array) уникальных ключей целевой модели."
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "Many to many (array)": "Many to many (array)",
3
+ "Many to many (array) description": "Allows to create many to many relationships between two models by storing an array of unique keys of the target model."
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "Many to many (array)": "Many to many (array)",
3
+ "Many to many (array) description": "Allows to create many to many relationships between two models by storing an array of unique keys of the target model."
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "Many to many (array)": "Many to many (array)",
3
+ "Many to many (array) description": "Allows to create many to many relationships between two models by storing an array of unique keys of the target model."
4
+ }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "Many to many (array)": "多对多(数组)",
3
3
  "Many to many (array) description": "支持通过在数组中存储目标表唯一键的方式建立多对多关系。"
4
- }
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "Many to many (array)": "Many to many (array)",
3
+ "Many to many (array) description": "Allows to create many to many relationships between two models by storing an array of unique keys of the target model."
4
+ }
@@ -11,6 +11,7 @@ export declare const elementTypeMap: {
11
11
  nanoid: string;
12
12
  sequence: string;
13
13
  uid: string;
14
+ snowflakeId: string;
14
15
  };
15
16
  export declare class BelongsToArrayField extends RelationField {
16
17
  get dataType(): string;
@@ -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 (!values || values[name] === void 0) {
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 = values[name] || [];
49
- if (!Array.isArray(value)) {
50
- value = [value];
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-alpha.9",
9
+ "version": "2.1.0-alpha.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": "4a9acf96f21a3aa35bccbd188b942595b09da0a9"
19
+ "gitHead": "d27baf21569643d6fa83f882233f4e90eb5b89f1"
18
20
  }