Skip to content

Commit

Permalink
skip updating paranoia_destroy_attributes for records while really_de…
Browse files Browse the repository at this point in the history
…stroy! (#535)
  • Loading branch information
kortirso authored Nov 15, 2022
1 parent c0d1d9a commit 09e3a9f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# paranoia Changelog

## 2.6.1

* [#535](https://github.com/rubysherpas/paranoia/pull/535) Allow to skip updating paranoia_destroy_attributes for records while really_destroy!
[Anton Bogdanov](https://github.com/kortirso)

## 2.6.0

* [#512](https://github.com/rubysherpas/paranoia/pull/512) Quote table names; Mysql 8 has keywords that might match table names which cause an exception.
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![Gem Version](https://badge.fury.io/rb/paranoia.svg)](https://badge.fury.io/rb/paranoia)
[![build](https://github.com/rubysherpas/paranoia/actions/workflows/build.yml/badge.svg)](https://github.com/rubysherpas/paranoia/actions/workflows/build.yml)

**Notice:**
**Notice:**

`paranoia` has some surprising behaviour (like overriding ActiveRecord's `delete` and `destroy`) and is not recommended for new projects. See [`discard`'s README](https://github.com/jhawthorn/discard#why-not-paranoia-or-acts_as_paranoid) for more details.

Expand Down Expand Up @@ -103,6 +103,14 @@ If you really want it gone *gone*, call `really_destroy!`:
# => client
```

If you need skip updating timestamps for deleting records, call `really_destroy!(update_destroy_attributes: false)`.
When we call `really_destroy!(update_destroy_attributes: false)` on the parent `client`, then each child `email` will also have `really_destroy!(update_destroy_attributes: false)` called.

``` ruby
>> client.really_destroy!(update_destroy_attributes: false)
# => client
```

If you want to use a column other than `deleted_at`, you can pass it as an option:

``` ruby
Expand Down
10 changes: 6 additions & 4 deletions lib/paranoia.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def paranoia_destroyed?
end
alias :deleted? :paranoia_destroyed?

def really_destroy!
def really_destroy!(update_destroy_attributes: true)
with_transaction_returning_status do
run_callbacks(:real_destroy) do
@_disable_counter_cache = paranoia_destroyed?
Expand All @@ -158,12 +158,14 @@ def really_destroy!
# .paranoid? will work for both instances and classes
next unless association_data && association_data.paranoid?
if reflection.collection?
next association_data.with_deleted.each(&:really_destroy!)
next association_data.with_deleted.find_each { |record|
record.really_destroy!(update_destroy_attributes: update_destroy_attributes)
}
end
association_data.really_destroy!
association_data.really_destroy!(update_destroy_attributes: update_destroy_attributes)
end
end
update_columns(paranoia_destroy_attributes)
update_columns(paranoia_destroy_attributes) if update_destroy_attributes
destroy_without_paranoia
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/paranoia/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Paranoia
VERSION = '2.6.0'.freeze
VERSION = '2.6.1'.freeze
end

0 comments on commit 09e3a9f

Please sign in to comment.