@nocobase/database 1.2.11-alpha → 1.2.12-alpha

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.js CHANGED
@@ -64,6 +64,8 @@ function EnsureAtomicity(target, propertyKey, descriptor) {
64
64
  const model = this.model;
65
65
  const beforeAssociationKeys = Object.keys(model.associations);
66
66
  const beforeRawAttributes = Object.keys(model.rawAttributes);
67
+ const fieldName = args[0];
68
+ const beforeField = this.getField(fieldName);
67
69
  try {
68
70
  return originalMethod.apply(this, args);
69
71
  } catch (error) {
@@ -77,6 +79,9 @@ function EnsureAtomicity(target, propertyKey, descriptor) {
77
79
  for (const key of createdRawAttributes) {
78
80
  delete this.model.rawAttributes[key];
79
81
  }
82
+ if (!beforeField) {
83
+ this.removeField(fieldName);
84
+ }
80
85
  throw error;
81
86
  }
82
87
  };
@@ -356,6 +356,9 @@ async function updateMultipleAssociation(model, key, value, options = {}) {
356
356
  if (throughValue) {
357
357
  accessorOptions["through"] = throughValue;
358
358
  }
359
+ if (pk !== targetKey && !isUndefinedOrNull(item[pk]) && isUndefinedOrNull(item[targetKey])) {
360
+ throw new Error(`${targetKey} field value is empty`);
361
+ }
359
362
  if (isUndefinedOrNull(item[targetKey])) {
360
363
  const instance = await model[createAccessor](item, accessorOptions);
361
364
  await updateAssociations(instance, item, {
@@ -138,6 +138,7 @@ const _UpdateGuard = class _UpdateGuard {
138
138
  let associationValues = associationsValues[association];
139
139
  const associationObj = associations[association];
140
140
  const filterAssociationToBeUpdate = /* @__PURE__ */ __name((value) => {
141
+ var _a;
141
142
  if (value === null) {
142
143
  return value;
143
144
  }
@@ -145,7 +146,7 @@ const _UpdateGuard = class _UpdateGuard {
145
146
  if (associationKeysToBeUpdate.includes(association)) {
146
147
  return value;
147
148
  }
148
- const associationKeyName = associationObj.targetKey ? associationObj.targetKey : associationObj.target.primaryKeyAttribute;
149
+ const associationKeyName = ((_a = associationObj == null ? void 0 : associationObj["options"]) == null ? void 0 : _a.targetKey) ? associationObj["options"].targetKey : associationObj.target.primaryKeyAttribute;
149
150
  if (value[associationKeyName]) {
150
151
  return import_lodash.default.pick(value, [associationKeyName, ...Object.keys(associationObj.target.associations)]);
151
152
  }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@nocobase/database",
3
- "version": "1.2.11-alpha",
3
+ "version": "1.2.12-alpha",
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.2.11-alpha",
10
- "@nocobase/utils": "1.2.11-alpha",
9
+ "@nocobase/logger": "1.2.12-alpha",
10
+ "@nocobase/utils": "1.2.12-alpha",
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": "251ff80e1ae6c0a9b4892fc6986dcdc0f5518fe8"
41
+ "gitHead": "553231d4882496cb7f1f17fa7541899ce82a27ab"
42
42
  }