aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-10-21 15:08:51 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-10-21 15:08:51 -0700
commitdb994076946f44d9b0fea23ca8715a74cb1f2b87 (patch)
tree375dbd4e1ec577c3871c5e9201cbb0f74f5fe410 /activerecord
parent8f5647e9c55f46aeeb01baef31d696c7a4415104 (diff)
downloadrails-db994076946f44d9b0fea23ca8715a74cb1f2b87.tar.gz
rails-db994076946f44d9b0fea23ca8715a74cb1f2b87.tar.bz2
rails-db994076946f44d9b0fea23ca8715a74cb1f2b87.zip
build the association graph functionally
This lets us avoid the constant calls to Array#<<
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations/join_dependency.rb25
-rw-r--r--activerecord/lib/active_record/associations/join_dependency/join_association.rb4
-rw-r--r--activerecord/lib/active_record/associations/join_dependency/join_part.rb4
3 files changed, 13 insertions, 20 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb
index 20457e9e57..4bcd69c69b 100644
--- a/activerecord/lib/active_record/associations/join_dependency.rb
+++ b/activerecord/lib/active_record/associations/join_dependency.rb
@@ -52,11 +52,10 @@ module ActiveRecord
# joins #=> []
#
def initialize(base, associations, joins)
- @join_root = JoinBase.new(base)
@alias_tracker = AliasTracker.new(base.connection, joins)
@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
+ @join_root = JoinBase.new base, build(tree, base)
@join_root.children.each { |child| construct_tables! @join_root, child }
end
@@ -212,23 +211,17 @@ module ActiveRecord
raise ConfigurationError, "Association named '#{ name }' was not found on #{ klass.name }; perhaps you misspelled it?"
end
- def build(associations, parent)
- associations.each do |name, right|
- reflection = find_reflection parent.base_klass, name
- join_association = build_join_association reflection
- parent.children << join_association
- build right, join_association
- end
- end
+ def build(associations, base_klass)
+ associations.map do |name, right|
+ reflection = find_reflection base_klass, name
+ reflection.check_validity!
- def build_join_association(reflection)
- reflection.check_validity!
+ if reflection.options[:polymorphic]
+ raise EagerLoadPolymorphicError.new(reflection)
+ end
- if reflection.options[:polymorphic]
- raise EagerLoadPolymorphicError.new(reflection)
+ JoinAssociation.new reflection, build(right, reflection.klass)
end
-
- JoinAssociation.new(reflection)
end
def construct(ar_parent, parent, row, rs, seen, model_cache, aliases)
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 d2c090ae56..191d430636 100644
--- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb
+++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb
@@ -9,8 +9,8 @@ module ActiveRecord
attr_accessor :tables
- def initialize(reflection)
- super(reflection.klass)
+ def initialize(reflection, children)
+ super(reflection.klass, children)
@reflection = reflection
@tables = nil
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 e22232168d..91e1c6a9d7 100644
--- a/activerecord/lib/active_record/associations/join_dependency/join_part.rb
+++ b/activerecord/lib/active_record/associations/join_dependency/join_part.rb
@@ -17,10 +17,10 @@ module ActiveRecord
delegate :table_name, :column_names, :primary_key, :to => :base_klass
- def initialize(base_klass)
+ def initialize(base_klass, children)
@base_klass = base_klass
@column_names_with_alias = nil
- @children = []
+ @children = children
end
def name