diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-01-14 06:50:25 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-01-14 06:50:25 +0900 |
commit | e9c16536d462503abd37e0ce5c34032fc1e39fdb (patch) | |
tree | f80b87f436a9736fd0d215f73573c8dcef794478 /activerecord | |
parent | 0c743885baba1681ad43376f6444b52a306fdfd9 (diff) | |
download | rails-e9c16536d462503abd37e0ce5c34032fc1e39fdb.tar.gz rails-e9c16536d462503abd37e0ce5c34032fc1e39fdb.tar.bz2 rails-e9c16536d462503abd37e0ce5c34032fc1e39fdb.zip |
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.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/associations/alias_tracker.rb | 12 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/finder_methods.rb | 3 |
2 files changed, 4 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/associations/alias_tracker.rb b/activerecord/lib/active_record/associations/alias_tracker.rb index 14881cfe17..4f3893588e 100644 --- a/activerecord/lib/active_record/associations/alias_tracker.rb +++ b/activerecord/lib/active_record/associations/alias_tracker.rb @@ -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 diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index 98992caa0c..5f959af5dc 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -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 |