-
-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(query): make WhereDeleted compatible with ForceDelete
As of Bun 1.1.8, `WhereDeleted()` is ignored when used with `ForceDelete()`. This commit fixes that problem: ```go db.NewDelete().Model((*Model)(nil)).Where("1 = 1").WhereDeleted().ForceDelete().Exec(ctx) // Before this commit: DELETE FROM model WHERE 1 = 1 // After this commit: DELETE FROM model WHERE 1 = 1 AND deleted_at IS NOT NULL ``` Additionally, the `Where("1 = 1")` trick is no longer required as `WhereDeleted()` now counts as a user-defined `WHERE` clause in `mustAppendWhere`: ```go db.NewDelete().Model((*Model)(nil)).WhereDeleted().ForceDelete().Exec(ctx) // Before this commit: Errors with "bun: Update and Delete queries require at least one Where" // After this commit: DELETE FROM model WHERE deleted_at IS NOT NULL ``` This gives us an easy and natural way to hard delete all soft deleted records. Fixes #673.
- Loading branch information
1 parent
d368bbe
commit 299c3fd
Showing
3 changed files
with
39 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters