ReviewOS

also looking at this

stacks/bun-query-builder

fix(orm)!: destroy() honours soft deletes, and forceDelete() purges

#1159
Merged glennmichael123 wants to merge fix/destroy-honours-soft-deletes into main
4 files +254 -7
docs/delete.mdmodified+23-0
Changes to docs/delete.md
@@ -126,6 +126,29 @@ await db
126126
127127```
128128
129## Deleting by id on a Model
130
131`Model.delete(id)` and `Model.destroy(id)` both delete the row the way an
132instance 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
134trashed, which they no longer see. Use `Model.forceDelete(id)` to purge that.
135
136```typescript
137await Post.delete(1) // or Post.destroy(1) — the same call
138await 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
142row 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
146await Post.forceDelete(1) // or Post.remove(1)
147```
148
149An instance has the same pair: `post.delete()` marks a soft-deletable row,
150`post.forceDelete()` removes it.
151
129152## Delete with Returning
130153
131154```typescript