also looking at this
fix(orm)!: destroy() honours soft deletes, and forceDelete() purges
#1159
4 files
+254
-7
| @@ -126,6 +126,29 @@ await db | ||
| 126 | 126 | |
| 127 | 127 | ``` |
| 128 | 128 | |
| 129 | ## Deleting by id on a Model | |
| 130 | ||
| 131 | `Model.delete(id)` and `Model.destroy(id)` both delete the row the way an | |
| 132 | instance does: a model with `useSoftDeletes` is marked rather than removed, and | |
| 133 | `beforeDelete`/`afterDelete` run. Both answer `false` when there is no such row — including one that is already | |
| 134 | trashed, which they no longer see. Use `Model.forceDelete(id)` to purge that. | |
| 135 | ||
| 136 | ```typescript | |
| 137 | await Post.delete(1) // or Post.destroy(1) — the same call | |
| 138 | await Post.onlyTrashed().first() // the row is still there, marked | |
| 139 | ``` | |
| 140 | ||
| 141 | `Model.forceDelete(id)` removes it for good, soft deletes or not, and finds a | |
| 142 | row that is already trashed. `Model.remove(id)` is the same call, matching what | |
| 143 | `db.remove(table, id)` means above. Delete hooks run either way. | |
| 144 | ||
| 145 | ```typescript | |
| 146 | await Post.forceDelete(1) // or Post.remove(1) | |
| 147 | ``` | |
| 148 | ||
| 149 | An instance has the same pair: `post.delete()` marks a soft-deletable row, | |
| 150 | `post.forceDelete()` removes it. | |
| 151 | ||
| 129 | 152 | ## Delete with Returning |
| 130 | 153 | |
| 131 | 154 | ```typescript |