rails_delete_all_and_assocs_without_instantiation 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cef795591d41dcdd1dfbb7c64f25d1e070640dad50d2635e605a7315be0f4bd3
|
4
|
+
data.tar.gz: 930cbbdee057d7444db66ce1855b8ca9b6e1f42f8ec9e67e88b45c8a2d9ff830
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4a7553953c99a07638e27294dd28db610accb1bc6db8c07ef43f2ea13ee47fd5ec34dfd57a6a0b40115047c3925475c1f3234691a4db5037773d33ebf6006ed
|
7
|
+
data.tar.gz: ad2091ccff93424d1616bcca3eff51f9af9592245d1846b95a4d91509247072685bc777b7c54687dd35854d50e1b3ccaf6fca4e06f45a9445f389246244b17ab
|
data/lib/rails_delete_all_and_assocs_without_instantiation/delete_all_and_assocs_extension.rb
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
module RailsDeleteAllAndAssocsWithoutInstantiation
|
2
2
|
module DeleteAllAndAssocsWithoutInstantiation
|
3
|
+
MATCH_DEPENDENT_ASSOC_VALUE = [
|
4
|
+
:destroy,
|
5
|
+
'destroy',
|
6
|
+
:delete_all,
|
7
|
+
'delete_all',
|
8
|
+
:destroy_async,
|
9
|
+
'destroy_async',
|
10
|
+
]
|
3
11
|
|
4
12
|
# rails interpretation is different than expected:
|
5
13
|
# https://makandracards.com/makandra/32175-don-t-forget-automatically-remove-join-records-on-has_many-through-associations
|
@@ -22,7 +30,7 @@ module RailsDeleteAllAndAssocsWithoutInstantiation
|
|
22
30
|
# force_through_destroy_chains = options[:force_destroy_chain] || {}
|
23
31
|
# do_not_destroy_self = options[:do_not_destroy] || {}
|
24
32
|
|
25
|
-
current_class = self
|
33
|
+
current_class = self.name
|
26
34
|
current_query = self
|
27
35
|
ids = current_query.pluck(:id)
|
28
36
|
models_and_ids_list[name] ||= []
|
@@ -33,14 +41,14 @@ module RailsDeleteAllAndAssocsWithoutInstantiation
|
|
33
41
|
return models_and_ids_list, errors
|
34
42
|
end
|
35
43
|
|
36
|
-
models_and_ids_list[self.name]
|
44
|
+
models_and_ids_list[self.name] += ids
|
37
45
|
|
38
46
|
# if do_not_destroy_self != true
|
39
47
|
# models_and_ids_list[name] += ids
|
40
48
|
# end
|
41
49
|
|
42
50
|
# ignore associations that aren't dependent destroyable.
|
43
|
-
destroy_association_names = self.reflect_on_all_associations.reject{|v| !
|
51
|
+
destroy_association_names = self.reflect_on_all_associations.reject{|v| !MATCH_DEPENDENT_ASSOC_VALUE.include?(v.options&.dig(:dependent)) }.collect{ |v| v.name }
|
44
52
|
|
45
53
|
|
46
54
|
# associations that we might not necessarilly need to delete, but need to go through
|
@@ -145,6 +153,11 @@ module RailsDeleteAllAndAssocsWithoutInstantiation
|
|
145
153
|
retry_due_to_errors = []
|
146
154
|
retry_to_capture_errors = []
|
147
155
|
|
156
|
+
if options[:verbose]
|
157
|
+
puts "DELETION STRUCTURE"
|
158
|
+
puts built_deletions.inspect
|
159
|
+
end
|
160
|
+
|
148
161
|
ActiveRecord::Base.transaction do
|
149
162
|
built_deletions.keys.reverse.each do |class_name|
|
150
163
|
begin
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{rails_delete_all_and_assocs_without_instantiation}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.3"
|
6
6
|
s.date = %q{2023-03-02}
|
7
7
|
s.authors = ["benjamin.dana.software.dev@gmail.com"]
|
8
8
|
s.summary = %q{Non-instantiated way of deleting records with dependencies quickly without instantiation.}
|