@bedrockio/model 0.2.13 → 0.2.15

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.
@@ -244,6 +244,9 @@ async function deleteLocalReferences(doc, arr) {
244
244
  for (let name of arr) {
245
245
  await doc.populate(name);
246
246
  const value = doc.get(name);
247
+ if (!value) {
248
+ continue;
249
+ }
247
250
  const arr = Array.isArray(value) ? value : [value];
248
251
  for (let sub of arr) {
249
252
  await sub.delete();
@@ -36,7 +36,11 @@ function applyQueries(schema) {
36
36
  this.deleted = true;
37
37
  this.deletedAt = new Date();
38
38
  // @ts-ignore
39
- return this.save();
39
+ return this.save({
40
+ // Do not validate when soft deleting the data is effectively
41
+ // gone for now, however ensure that we do validate when restoring.
42
+ validateBeforeSave: false
43
+ });
40
44
  });
41
45
  schema.method('restore', function restore() {
42
46
  this.deleted = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bedrockio/model",
3
- "version": "0.2.13",
3
+ "version": "0.2.15",
4
4
  "description": "Bedrock utilities for model creation.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -235,9 +235,13 @@ async function deleteLocalReferences(doc, arr) {
235
235
  }
236
236
  for (let name of arr) {
237
237
  await doc.populate(name);
238
+
238
239
  const value = doc.get(name);
239
- const arr = Array.isArray(value) ? value : [value];
240
+ if (!value) {
241
+ continue;
242
+ }
240
243
 
244
+ const arr = Array.isArray(value) ? value : [value];
241
245
  for (let sub of arr) {
242
246
  await sub.delete();
243
247
  }
@@ -29,7 +29,11 @@ function applyQueries(schema) {
29
29
  this.deleted = true;
30
30
  this.deletedAt = new Date();
31
31
  // @ts-ignore
32
- return this.save();
32
+ return this.save({
33
+ // Do not validate when soft deleting the data is effectively
34
+ // gone for now, however ensure that we do validate when restoring.
35
+ validateBeforeSave: false,
36
+ });
33
37
  });
34
38
 
35
39
  schema.method('restore', function restore() {
@@ -1 +1 @@
1
- {"version":3,"file":"soft-delete.d.ts","sourceRoot":"","sources":["../src/soft-delete.js"],"names":[],"mappings":"AAKA,mDAIC;AAoTD,oEAsBC;AAgDD,2DAKC"}
1
+ {"version":3,"file":"soft-delete.d.ts","sourceRoot":"","sources":["../src/soft-delete.js"],"names":[],"mappings":"AAKA,mDAIC;AAwTD,oEAsBC;AAgDD,2DAKC"}