strict_associations 0.1.6 → 0.1.7
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/CHANGELOG.md +2 -2
- data/lib/strict_associations/validator.rb +11 -14
- data/lib/strict_associations/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: fbe650347474030e15a049132a0e002e1a0dd421fd747d6b0a4c6cc2e8efce91
|
|
4
|
+
data.tar.gz: 31ba848896030b174536c90bca7f4970a24272958bb8f15b7d85c03897ad0da7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d290a381bce9063d13f5f6134145b4d05883681a28e3ac4b9fc44415846e7e0561ecdfdbe48572febfb8341f764c96ce1b68fe61ac2ee3715257c4d0e044ce21
|
|
7
|
+
data.tar.gz: 4d872852b7716e934d3271af605f6264714601d262f0c1bdc7841310e4a1251c0acaffc82f4fa4610e552a5348bc4c5f317b07cd8eb55149f8b90609049219b7
|
data/CHANGELOG.md
CHANGED
|
@@ -241,16 +241,16 @@ module StrictAssociations
|
|
|
241
241
|
return unless owns_table?(model)
|
|
242
242
|
|
|
243
243
|
is_third_party = third_party?(model)
|
|
244
|
-
|
|
244
|
+
fk_columns = database_foreign_key_columns(model)
|
|
245
245
|
defined_fk_columns = sti_family_foreign_keys(model)
|
|
246
246
|
|
|
247
|
-
(
|
|
247
|
+
(fk_columns - defined_fk_columns).each do |column|
|
|
248
248
|
assoc_name = column.delete_suffix("_id").to_sym
|
|
249
249
|
next if model.strict_association_skipped?(assoc_name)
|
|
250
250
|
|
|
251
251
|
msg = if is_third_party
|
|
252
252
|
<<~MSG.squish
|
|
253
|
-
#{model} (third-party) has
|
|
253
|
+
#{model} (third-party) has a foreign key #{column} \
|
|
254
254
|
with no corresponding belongs_to. If this FK references \
|
|
255
255
|
one of your models, define a has_many on your model \
|
|
256
256
|
pointing back. Or call skip_strict_association \
|
|
@@ -258,11 +258,12 @@ module StrictAssociations
|
|
|
258
258
|
MSG
|
|
259
259
|
else
|
|
260
260
|
<<~MSG.squish
|
|
261
|
-
#{model.table_name} has
|
|
261
|
+
#{model.table_name} has a foreign key #{column} but \
|
|
262
262
|
#{model} has no belongs_to association for it.
|
|
263
263
|
Define a belongs_to.
|
|
264
|
-
Or remove the
|
|
265
|
-
Or call skip_strict_association :#{assoc_name}
|
|
264
|
+
Or remove the foreign key.
|
|
265
|
+
Or call skip_strict_association :#{assoc_name} \
|
|
266
|
+
on #{model}.
|
|
266
267
|
MSG
|
|
267
268
|
end
|
|
268
269
|
|
|
@@ -291,14 +292,10 @@ module StrictAssociations
|
|
|
291
292
|
end.uniq
|
|
292
293
|
end
|
|
293
294
|
|
|
294
|
-
def
|
|
295
|
-
model.connection
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
next unless columns.first.end_with?("_id")
|
|
299
|
-
|
|
300
|
-
columns.first
|
|
301
|
-
end
|
|
295
|
+
def database_foreign_key_columns(model)
|
|
296
|
+
model.connection
|
|
297
|
+
.foreign_keys(model.table_name)
|
|
298
|
+
.map(&:column)
|
|
302
299
|
end
|
|
303
300
|
|
|
304
301
|
def resolve_target(reflection)
|