Skip to content

Commit

Permalink
Adds Model#delete
Browse files Browse the repository at this point in the history
  • Loading branch information
swiknaba committed Jan 2, 2024
1 parent 94a1222 commit 89e5561
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/kirei/base_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ def update(hash)
self.class.find_by({ id: id })
end

# Delete keeps the original object intact. Returns true if the record was deleted.
# Calling delete multiple times will return false after the first (successful) call.
sig { returns(T::Boolean) }
def delete
count = self.class.db.where({ id: id }).delete
count == 1
end

# warning: this is not concurrency-safe
# save keeps the original object intact, and returns a new object with the updated values.
sig { returns(T.self_type) }
Expand Down

0 comments on commit 89e5561

Please sign in to comment.