diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-15 15:34:59 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-15 15:34:59 -0700 |
commit | c746b5339087825b1fe79abc426170baf1b51e5c (patch) | |
tree | 4f82cb5984df05ab618f7b98d7cb688fd4311d64 /activerecord/lib/active_record/associations | |
parent | db2e21aa0eed26835d02b874ce97afa6c8abd3e2 (diff) | |
download | rails-c746b5339087825b1fe79abc426170baf1b51e5c.tar.gz rails-c746b5339087825b1fe79abc426170baf1b51e5c.tar.bz2 rails-c746b5339087825b1fe79abc426170baf1b51e5c.zip |
apply table aliases after the AST has been built
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency.rb | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index 66cc5bd3ac..f16013ff6a 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -58,6 +58,9 @@ module ActiveRecord @alias_tracker.aliased_name_for(base.table_name) # Updates the count for base.table_name to 1 tree = self.class.make_tree associations build tree, @join_root, Arel::InnerJoin + @join_root.children.each do |child| + apply_tables! @join_root, child + end end def reflections @@ -76,6 +79,9 @@ module ActiveRecord deep_copy left, node } end + @join_root.children.each do |child| + apply_tables! @join_root, child + end end def join_constraints @@ -165,6 +171,8 @@ module ActiveRecord end def construct_tables!(parent, node) + return if node.tables + node.tables = node.reflection.chain.map { |reflection| alias_tracker.aliased_table_for( reflection.table_name, @@ -217,10 +225,14 @@ module ActiveRecord end node = JoinAssociation.new(reflection, join_type) - construct_tables!(parent, node) node end + def apply_tables!(parent, node) + construct_tables!(parent, node) + node.children.each { |child| apply_tables! node, child } + end + def construct(ar_parent, parent, row, rs, seen, model_cache, aliases) primary_id = ar_parent.id |