foreign_key_checker 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/foreign_key_checker.rb +9 -0
- data/lib/foreign_key_checker/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cefd15f97041e89257c6487ba55dfeed549c4b97abcd577af614e38a2a23c54b
|
4
|
+
data.tar.gz: 322939db9133f937b95bb7f7324c418eae65758a0f4c50f422abc0387e7706ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8a8b3c7e1e308935781008935029c850d57db6cfb17127eced235580f3b2eaf75dcd9d2b8d1692130e4f83f6dabead19410fe7d15c886b1105b3524a66db60e
|
7
|
+
data.tar.gz: aab87280fdcba657ac5737ac4bf793713528d689f95d7a73ffaa558f3ab75bc107af6b61dd635b6faaa7a6df143973cf77e618b2687013d10f930ff0184a2ca2
|
data/lib/foreign_key_checker.rb
CHANGED
@@ -210,6 +210,13 @@ module ForeignKeyChecker
|
|
210
210
|
)
|
211
211
|
end
|
212
212
|
|
213
|
+
def already_done_fk?(model, association)
|
214
|
+
@_done ||= {}
|
215
|
+
ret = @_done[[model.table_name, association.foreign_key]]
|
216
|
+
@_done[[model.table_name, association.foreign_key]] = true
|
217
|
+
ret
|
218
|
+
end
|
219
|
+
|
213
220
|
def check
|
214
221
|
Rails.application.eager_load!
|
215
222
|
ActiveRecord::Base.descendants.each do |model|
|
@@ -217,11 +224,13 @@ module ForeignKeyChecker
|
|
217
224
|
next if excluded_specification?(model)
|
218
225
|
|
219
226
|
model.reflect_on_all_associations(:belongs_to).each do |association|
|
227
|
+
|
220
228
|
if association.options[:polymorphic] && polymorphic_zombies
|
221
229
|
check_polymorphic_bt_association(model, association)
|
222
230
|
next
|
223
231
|
end
|
224
232
|
|
233
|
+
next if already_done_fk?(model, association)
|
225
234
|
check_foreign_key_bt_association(model, association)
|
226
235
|
end
|
227
236
|
end
|