@nocobase/plugin-field-m2m-array 1.6.0-alpha.2 → 1.6.0-alpha.20

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,10 @@ module.exports = {
11
11
  "@formily/react": "2.3.0",
12
12
  "antd": "5.12.8",
13
13
  "react": "18.2.0",
14
- "@nocobase/client": "1.6.0-alpha.2",
14
+ "@nocobase/client": "1.6.0-alpha.20",
15
15
  "react-router-dom": "6.21.0",
16
- "@nocobase/utils": "1.6.0-alpha.2",
17
- "@nocobase/database": "1.6.0-alpha.2",
18
- "@nocobase/server": "1.6.0-alpha.2",
19
- "@nocobase/data-source-manager": "1.6.0-alpha.2"
16
+ "@nocobase/utils": "1.6.0-alpha.20",
17
+ "@nocobase/database": "1.6.0-alpha.20",
18
+ "@nocobase/server": "1.6.0-alpha.20",
19
+ "@nocobase/data-source-manager": "1.6.0-alpha.20"
20
20
  };
@@ -15,7 +15,6 @@ export declare const elementTypeMap: {
15
15
  export declare class BelongsToArrayField extends RelationField {
16
16
  get dataType(): string;
17
17
  private setForeignKeyArray;
18
- init(): void;
19
18
  checkTargetCollection(): boolean;
20
19
  checkAssociationKeys(): void;
21
20
  bind(): boolean;
@@ -45,7 +45,10 @@ class BelongsToArrayField extends import_database.RelationField {
45
45
  if (!values || values[name] === void 0) {
46
46
  return;
47
47
  }
48
- const value = values[name] || [];
48
+ let value = values[name] || [];
49
+ if (!Array.isArray(value)) {
50
+ value = [value];
51
+ }
49
52
  const tks = [];
50
53
  const items = [];
51
54
  for (const item of value) {
@@ -70,16 +73,6 @@ class BelongsToArrayField extends import_database.RelationField {
70
73
  tks.push(...newInstances.map((instance) => instance[targetKey]));
71
74
  model.set(foreignKey, tks);
72
75
  };
73
- init() {
74
- super.init();
75
- const { name, ...opts } = this.options;
76
- this.collection.model.associations[name] = new import_database.BelongsToArrayAssociation({
77
- db: this.database,
78
- source: this.collection.model,
79
- as: name,
80
- ...opts
81
- });
82
- }
83
76
  checkTargetCollection() {
84
77
  const { target } = this.options;
85
78
  if (!target) {
@@ -124,6 +117,13 @@ class BelongsToArrayField extends import_database.RelationField {
124
117
  return false;
125
118
  }
126
119
  this.checkAssociationKeys();
120
+ const { name, ...opts } = this.options;
121
+ this.collection.model.associations[name] = new import_database.BelongsToArrayAssociation({
122
+ db: this.database,
123
+ source: this.collection.model,
124
+ as: name,
125
+ ...opts
126
+ });
127
127
  this.on("beforeSave", this.setForeignKeyArray);
128
128
  }
129
129
  unbind() {
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "数据表字段:多对多 (数组)",
5
5
  "description": "Allows to create many to many relationships between two models by storing an array of unique keys of the target model.",
6
6
  "description.zh-CN": "支持通过在数组中存储目标表唯一键的方式建立多对多关系。",
7
- "version": "1.6.0-alpha.2",
7
+ "version": "1.6.0-alpha.20",
8
8
  "main": "dist/server/index.js",
9
9
  "peerDependencies": {
10
10
  "@nocobase/client": "1.x",
@@ -14,5 +14,5 @@
14
14
  "keywords": [
15
15
  "Collection fields"
16
16
  ],
17
- "gitHead": "08bbc34c21727fc0ad0880f397a42bf7741091ee"
17
+ "gitHead": "c127664eb2b900edd5c18c9344046cd663a06c3b"
18
18
  }