aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-10-11 10:49:13 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-10-11 11:07:15 -0700
commit085bb239f8476003fa06f81e06a7b4a0402401fc (patch)
treeaf8076062e40e2b953715fde1cea2418279d90e4 /activerecord/lib/active_record/associations
parent2550acc779877720710cfaca120196109da70c04 (diff)
downloadrails-085bb239f8476003fa06f81e06a7b4a0402401fc.tar.gz
rails-085bb239f8476003fa06f81e06a7b4a0402401fc.tar.bz2
rails-085bb239f8476003fa06f81e06a7b4a0402401fc.zip
pull parent and alias tacker from the nodes.
For now, we'll set the tables on the nodes manually.
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r--activerecord/lib/active_record/associations/join_dependency.rb19
-rw-r--r--activerecord/lib/active_record/associations/join_dependency/join_association.rb13
-rw-r--r--activerecord/lib/active_record/associations/join_dependency/join_base.rb4
-rw-r--r--activerecord/lib/active_record/associations/join_dependency/join_part.rb7
4 files changed, 23 insertions, 20 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb
index ead2668250..e4fc013e1c 100644
--- a/activerecord/lib/active_record/associations/join_dependency.rb
+++ b/activerecord/lib/active_record/associations/join_dependency.rb
@@ -117,6 +117,21 @@ module ActiveRecord
}
end
+ def construct_tables!(parent, node)
+ node.tables = node.reflection.chain.map { |reflection|
+ alias_tracker.aliased_table_for(
+ reflection.table_name,
+ table_alias_for(reflection, parent, reflection != node.reflection)
+ )
+ }.reverse
+ end
+
+ def table_alias_for(reflection, parent, join)
+ name = "#{reflection.plural_name}_#{parent.table_name}"
+ name << "_join" if join
+ name
+ end
+
def merge_node(left, right)
intersection, missing = right.children.map { |node1|
[left.children.find { |node2| node1.match? node2 }, node1]
@@ -187,7 +202,9 @@ module ActiveRecord
raise EagerLoadPolymorphicError.new(reflection)
end
- JoinAssociation.new(reflection, join_root.to_a.length, parent, join_type, alias_tracker)
+ node = JoinAssociation.new(reflection, join_root.to_a.length, join_type)
+ construct_tables!(parent, node)
+ node
end
def construct(ar_parent, parent, row, rs)
diff --git a/activerecord/lib/active_record/associations/join_dependency/join_association.rb b/activerecord/lib/active_record/associations/join_dependency/join_association.rb
index 0d3834240c..63f084426b 100644
--- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb
+++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb
@@ -15,24 +15,19 @@ module ActiveRecord
# These implement abstract methods from the superclass
attr_reader :aliased_prefix
- attr_reader :tables
- attr_reader :alias_tracker
+ attr_accessor :tables
delegate :options, :through_reflection, :source_reflection, :chain, :to => :reflection
- def initialize(reflection, index, parent, join_type, alias_tracker)
- super(reflection.klass, parent)
+ def initialize(reflection, index, join_type)
+ super(reflection.klass)
@reflection = reflection
- @alias_tracker = alias_tracker
@join_type = join_type
@aliased_prefix = "t#{ index }"
- @tables = construct_tables.reverse
+ @tables = nil
end
- def parent_table_name; parent.table_name; end
- alias :alias_suffix :parent_table_name
-
def match?(other)
return true if self == other
super && reflection == other.reflection
diff --git a/activerecord/lib/active_record/associations/join_dependency/join_base.rb b/activerecord/lib/active_record/associations/join_dependency/join_base.rb
index 48de12bcd5..de03f7097d 100644
--- a/activerecord/lib/active_record/associations/join_dependency/join_base.rb
+++ b/activerecord/lib/active_record/associations/join_dependency/join_base.rb
@@ -4,10 +4,6 @@ module ActiveRecord
module Associations
class JoinDependency # :nodoc:
class JoinBase < JoinPart # :nodoc:
- def initialize(klass)
- super(klass, nil)
- end
-
def match?(other)
return true if self == other
super && base_klass == other.base_klass
diff --git a/activerecord/lib/active_record/associations/join_dependency/join_part.rb b/activerecord/lib/active_record/associations/join_dependency/join_part.rb
index d39ce94c99..3ea5ee0e16 100644
--- a/activerecord/lib/active_record/associations/join_dependency/join_part.rb
+++ b/activerecord/lib/active_record/associations/join_dependency/join_part.rb
@@ -10,10 +10,6 @@ module ActiveRecord
class JoinPart # :nodoc:
include Enumerable
- # A JoinBase instance representing the active record we are joining onto.
- # (So in Author.has_many :posts, the Author would be that base record.)
- attr_reader :parent
-
# The Active Record class which this join part is associated 'about'; for a JoinBase
# this is the actual base model, for a JoinAssociation this is the target model of the
# association.
@@ -21,9 +17,8 @@ module ActiveRecord
delegate :table_name, :column_names, :primary_key, :arel_engine, :to => :base_klass
- def initialize(base_klass, parent)
+ def initialize(base_klass)
@base_klass = base_klass
- @parent = parent
@cached_record = {}
@column_names_with_alias = nil
@children = []