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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3f819414a8d4be6870c5852a87d82ea0aa73c7f0fed2f1495a04c82b2af73c4
4
- data.tar.gz: a6033ed16295800065be0325cddae7ecfa5c6d231f4c04242e3c25eec45a7345
3
+ metadata.gz: d3840cb8da5c485000f4837ba8eb88d348ed314157e726746334a25ba902c9eb
4
+ data.tar.gz: abe99225f8efdeb73b5425d1e6ae161e7c441fd556d36e08849e6da8d2fa36d2
5
5
  SHA512:
6
- metadata.gz: 16b986565c7ab65b619b9c2ee2ef764ebffa4462d054d1ff692bd10138791466f502c59386a168ef4a5d4647fcdd4a6a02f1619ce21927822303ed566e1b0939
7
- data.tar.gz: b9a04a6e00b0b0c07d3cf1a5f62e855bbb7c04b820357e506c38ebf857ccfa242251556f63e39172501932b25446b028678947f8ff7b34d74ef1603c27fb4732
6
+ metadata.gz: d8773b7689493980c772e795e5d4c601abd268e715baa74db4b83c9e88fd80e4a3c9dbd603fc8b0573125d491a391a5fac3cef6a9cab01106656b1952ff2dd3b
7
+ data.tar.gz: 249247cb1a40bf234d2aeb77ba209e732390b6bbaf861543b986e01b192d8d9083a991f1ad0d100fee6038db638620447ec62f1c4e871967d1576c0cee66c912
data/CHANGELOG.md CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
 
4
4
 
5
- ## [0.1.5] - Unreleased
5
+ ## [0.1.6] - Unreleased
6
6
 
7
- ## [0.1.4] - Unreleased
7
+ ## [0.1.5] - Unreleased
@@ -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
- violations << Violation.new(
252
- model:,
253
- association_name: assoc_name,
254
- rule: :orphaned_foreign_key,
255
- message: <<~MSG.squish
256
- #{model.table_name} has an indexed column #{column} but #{model} has no \
257
- belongs_to association for it.
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StrictAssociations
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.6"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strict_associations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Lange