1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Don't pass garbage args to alias tracker

This is a complete fix to #30995.

Originally alias tracker will only track table aliases on
`Arel::Nodes::Join`, other args are ignored.

Since c5ab6e5, parent aliases hash will be passed then it caused the
regression #30995.

It is enough to pass list of `Arel::Nodes::Join` simply, not need to
pass garbage args which will be ignored.
This commit is contained in:
Ryuta Kamizono 2018-01-14 06:50:25 +09:00
parent 0c743885ba
commit e9c16536d4
2 changed files with 4 additions and 11 deletions

View file

@ -30,20 +30,12 @@ module ActiveRecord
join.left.scan(
/JOIN(?:\s+\w+)?\s+(?:\S+\s+)?(?:#{quoted_name}|#{name})\sON/i
).size
elsif join.respond_to? :left
elsif join.is_a?(Arel::Nodes::Join)
join.left.name == name ? 1 : 0
elsif join.is_a?(Hash)
join.fetch(name, 0)
else
# this branch is reached by two tests:
#
# activerecord/test/cases/associations/cascaded_eager_loading_test.rb:37
# with :posts
#
# activerecord/test/cases/associations/eager_test.rb:1133
# with :comments
#
0
raise ArgumentError, "joins list should be initialized by list of Arel::Nodes::Join"
end
end

View file

@ -373,8 +373,9 @@ module ActiveRecord
def construct_join_dependency(eager_loading: true)
including = eager_load_values + includes_values
joins = joins_values.select { |join| join.is_a?(Arel::Nodes::Join) }
ActiveRecord::Associations::JoinDependency.new(
klass, table, including, alias_tracker(joins_values), eager_loading: eager_loading
klass, table, including, alias_tracker(joins), eager_loading: eager_loading
)
end