Skip to content

Commit

Permalink
Add with_soft_deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcsmith committed Mar 16, 2020
1 parent ce234c3 commit a79816b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 1 addition & 3 deletions spec/soft_delete_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ describe "Avram soft delete" do
])
end

# Waiting on https://github.com/luckyframework/avram/issues/319
# 'with_soft_deleted' would do `.reset_where(&.soft_deleted)`
pending "can get soft deleted and kept records" do
it "can get soft deleted and kept records" do
kept_item = SoftDeletableItemBox.create &.kept
soft_deleted_item = SoftDeletableItemBox.create &.soft_deleted

Expand Down
2 changes: 2 additions & 0 deletions src/avram/soft_delete/model.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ module Avram::SoftDelete::Model
def soft_deleted? : Bool
!!soft_deleted_at
end

abstract def soft_deleted_at : Time?
end
6 changes: 6 additions & 0 deletions src/avram/soft_delete/query.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ module Avram::SoftDelete::Query
def only_soft_deleted
soft_deleted_at.is_not_nil
end

def with_soft_deleted
reset_where(&.soft_deleted_at)
end

abstract def soft_deleted_at
end

0 comments on commit a79816b

Please sign in to comment.