Skip to content

Commit 2a63106

Browse files
committed
make sure association last argument is a keyword hash
1 parent db89f72 commit 2a63106

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lib/helpers/parse_rails.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@
5656
add_callback :call_node, at: 'start' do |node|
5757
if node.receiver.nil? && %i[belongs_to has_one has_many has_and_belongs_to_many].include?(node.name)
5858
association_name = node.arguments.arguments.first.to_value
59-
option_elements = node.arguments.arguments.second&.elements
6059
options = {}
61-
if option_elements
60+
if node.arguments.arguments.length > 1 && node.arguments.arguments.last.is_a?(Prism::KeywordHashNode)
61+
option_elements = node.arguments.arguments.last.elements
6262
%i[foreign_key foreign_type polymorphic].each do |option_key|
6363
option_element = option_elements.find { |element| element.key.value == option_key.to_s }
6464
options[option_key] = option_element.value.to_value if option_element

lib/rails_best_practices/always_add_db_index.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
rails_tables.each do |table_name, table_info|
2323
belongs_to_associations = rails_models[:associations].select do |association|
2424
# find all belongs_to associations
25-
association[:class_name].tableize == table_name || association[:type] == 'belongs_to'
25+
association[:class_name].tableize == table_name && association[:type] == 'belongs_to'
2626
end
2727
polymorphic_belongs_to_associations = belongs_to_associations.select do |association|
2828
next false unless association[:polymorphic]

0 commit comments

Comments
 (0)