Skip to content

Commit 09e3a9f

Browse files
authored
skip updating paranoia_destroy_attributes for records while really_destroy! (#535)
1 parent c0d1d9a commit 09e3a9f

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# paranoia Changelog
22

3+
## 2.6.1
4+
5+
* [#535](https://github.com/rubysherpas/paranoia/pull/535) Allow to skip updating paranoia_destroy_attributes for records while really_destroy!
6+
[Anton Bogdanov](https://github.com/kortirso)
7+
38
## 2.6.0
49

510
* [#512](https://github.com/rubysherpas/paranoia/pull/512) Quote table names; Mysql 8 has keywords that might match table names which cause an exception.

README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[![Gem Version](https://badge.fury.io/rb/paranoia.svg)](https://badge.fury.io/rb/paranoia)
22
[![build](https://github.com/rubysherpas/paranoia/actions/workflows/build.yml/badge.svg)](https://github.com/rubysherpas/paranoia/actions/workflows/build.yml)
33

4-
**Notice:**
4+
**Notice:**
55

66
`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.
77

@@ -103,6 +103,14 @@ If you really want it gone *gone*, call `really_destroy!`:
103103
# => client
104104
```
105105

106+
If you need skip updating timestamps for deleting records, call `really_destroy!(update_destroy_attributes: false)`.
107+
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.
108+
109+
``` ruby
110+
>> client.really_destroy!(update_destroy_attributes: false)
111+
# => client
112+
```
113+
106114
If you want to use a column other than `deleted_at`, you can pass it as an option:
107115

108116
``` ruby

lib/paranoia.rb

+6-4
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def paranoia_destroyed?
144144
end
145145
alias :deleted? :paranoia_destroyed?
146146

147-
def really_destroy!
147+
def really_destroy!(update_destroy_attributes: true)
148148
with_transaction_returning_status do
149149
run_callbacks(:real_destroy) do
150150
@_disable_counter_cache = paranoia_destroyed?
@@ -158,12 +158,14 @@ def really_destroy!
158158
# .paranoid? will work for both instances and classes
159159
next unless association_data && association_data.paranoid?
160160
if reflection.collection?
161-
next association_data.with_deleted.each(&:really_destroy!)
161+
next association_data.with_deleted.find_each { |record|
162+
record.really_destroy!(update_destroy_attributes: update_destroy_attributes)
163+
}
162164
end
163-
association_data.really_destroy!
165+
association_data.really_destroy!(update_destroy_attributes: update_destroy_attributes)
164166
end
165167
end
166-
update_columns(paranoia_destroy_attributes)
168+
update_columns(paranoia_destroy_attributes) if update_destroy_attributes
167169
destroy_without_paranoia
168170
end
169171
end

lib/paranoia/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Paranoia
2-
VERSION = '2.6.0'.freeze
2+
VERSION = '2.6.1'.freeze
33
end

0 commit comments

Comments
 (0)