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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3840cb8da5c485000f4837ba8eb88d348ed314157e726746334a25ba902c9eb
4
- data.tar.gz: abe99225f8efdeb73b5425d1e6ae161e7c441fd556d36e08849e6da8d2fa36d2
3
+ metadata.gz: fbe650347474030e15a049132a0e002e1a0dd421fd747d6b0a4c6cc2e8efce91
4
+ data.tar.gz: 31ba848896030b174536c90bca7f4970a24272958bb8f15b7d85c03897ad0da7
5
5
  SHA512:
6
- metadata.gz: d8773b7689493980c772e795e5d4c601abd268e715baa74db4b83c9e88fd80e4a3c9dbd603fc8b0573125d491a391a5fac3cef6a9cab01106656b1952ff2dd3b
7
- data.tar.gz: 249247cb1a40bf234d2aeb77ba209e732390b6bbaf861543b986e01b192d8d9083a991f1ad0d100fee6038db638620447ec62f1c4e871967d1576c0cee66c912
6
+ metadata.gz: d290a381bce9063d13f5f6134145b4d05883681a28e3ac4b9fc44415846e7e0561ecdfdbe48572febfb8341f764c96ce1b68fe61ac2ee3715257c4d0e044ce21
7
+ data.tar.gz: 4d872852b7716e934d3271af605f6264714601d262f0c1bdc7841310e4a1251c0acaffc82f4fa4610e552a5348bc4c5f317b07cd8eb55149f8b90609049219b7
data/CHANGELOG.md CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
 
4
4
 
5
- ## [0.1.6] - Unreleased
5
+ ## [0.1.7] - Unreleased
6
6
 
7
- ## [0.1.5] - Unreleased
7
+ ## [0.1.6] - Unreleased
@@ -241,16 +241,16 @@ module StrictAssociations
241
241
  return unless owns_table?(model)
242
242
 
243
243
  is_third_party = third_party?(model)
244
- indexed_fk_columns = indexed_foreign_key_columns(model)
244
+ fk_columns = database_foreign_key_columns(model)
245
245
  defined_fk_columns = sti_family_foreign_keys(model)
246
246
 
247
- (indexed_fk_columns - defined_fk_columns).each do |column|
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 an indexed column #{column} \
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 an indexed column #{column} but \
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 index.
265
- Or call skip_strict_association :#{assoc_name} on #{model}.
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 indexed_foreign_key_columns(model)
295
- model.connection.indexes(model.table_name).filter_map do |index|
296
- columns = index.columns
297
- next unless columns.is_a?(Array) && columns.one?
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StrictAssociations
4
- VERSION = "0.1.6"
4
+ VERSION = "0.1.7"
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.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Lange