strict_associations 0.1.5 → 0.1.6
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 +20 -8
- 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: d3840cb8da5c485000f4837ba8eb88d348ed314157e726746334a25ba902c9eb
|
|
4
|
+
data.tar.gz: abe99225f8efdeb73b5425d1e6ae161e7c441fd556d36e08849e6da8d2fa36d2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d8773b7689493980c772e795e5d4c601abd268e715baa74db4b83c9e88fd80e4a3c9dbd603fc8b0573125d491a391a5fac3cef6a9cab01106656b1952ff2dd3b
|
|
7
|
+
data.tar.gz: 249247cb1a40bf234d2aeb77ba209e732390b6bbaf861543b986e01b192d8d9083a991f1ad0d100fee6038db638620447ec62f1c4e871967d1576c0cee66c912
|
data/CHANGELOG.md
CHANGED
|
@@ -238,9 +238,9 @@ module StrictAssociations
|
|
|
238
238
|
end
|
|
239
239
|
|
|
240
240
|
def check_orphaned_foreign_keys(model, violations)
|
|
241
|
-
return if third_party?(model)
|
|
242
241
|
return unless owns_table?(model)
|
|
243
242
|
|
|
243
|
+
is_third_party = third_party?(model)
|
|
244
244
|
indexed_fk_columns = indexed_foreign_key_columns(model)
|
|
245
245
|
defined_fk_columns = sti_family_foreign_keys(model)
|
|
246
246
|
|
|
@@ -248,17 +248,29 @@ module StrictAssociations
|
|
|
248
248
|
assoc_name = column.delete_suffix("_id").to_sym
|
|
249
249
|
next if model.strict_association_skipped?(assoc_name)
|
|
250
250
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
251
|
+
msg = if is_third_party
|
|
252
|
+
<<~MSG.squish
|
|
253
|
+
#{model} (third-party) has an indexed column #{column} \
|
|
254
|
+
with no corresponding belongs_to. If this FK references \
|
|
255
|
+
one of your models, define a has_many on your model \
|
|
256
|
+
pointing back. Or call skip_strict_association \
|
|
257
|
+
:#{assoc_name} on #{model}.
|
|
258
|
+
MSG
|
|
259
|
+
else
|
|
260
|
+
<<~MSG.squish
|
|
261
|
+
#{model.table_name} has an indexed column #{column} but \
|
|
262
|
+
#{model} has no belongs_to association for it.
|
|
258
263
|
Define a belongs_to.
|
|
259
264
|
Or remove the index.
|
|
260
265
|
Or call skip_strict_association :#{assoc_name} on #{model}.
|
|
261
266
|
MSG
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
violations << Violation.new(
|
|
270
|
+
model:,
|
|
271
|
+
association_name: assoc_name,
|
|
272
|
+
rule: :orphaned_foreign_key,
|
|
273
|
+
message: msg
|
|
262
274
|
)
|
|
263
275
|
end
|
|
264
276
|
end
|