aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-10-15 15:34:59 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-10-15 15:34:59 -0700
commitc746b5339087825b1fe79abc426170baf1b51e5c (patch)
tree4f82cb5984df05ab618f7b98d7cb688fd4311d64 /activerecord/lib/active_record
parentdb2e21aa0eed26835d02b874ce97afa6c8abd3e2 (diff)
downloadrails-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')
-rw-r--r--activerecord/lib/active_record/associations/join_dependency.rb14
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