aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2014-11-11 14:34:08 -0500
committereileencodes <eileencodes@gmail.com>2015-01-02 17:15:31 -0500
commit17f6ca1e8a69f08a14fd7ab23dfe63691cd976a7 (patch)
tree72e135381c7d624fbcd6f2dbbfc1f6d2fb062fbe
parent5b0b3cce5c0ecef02f1f6f09aea1de44b9ca88cf (diff)
downloadrails-17f6ca1e8a69f08a14fd7ab23dfe63691cd976a7.tar.gz
rails-17f6ca1e8a69f08a14fd7ab23dfe63691cd976a7.tar.bz2
rails-17f6ca1e8a69f08a14fd7ab23dfe63691cd976a7.zip
Refactor `#get_chain` to remove need for `#construct_tables`
By concatnating the `ReflectionProxy` with the `chain` we remove the need for `#construct_tables` because the `chain` is now in the correct order (order of the chain DOES matter).
-rw-r--r--activerecord/lib/active_record/associations/association_scope.rb25
1 files changed, 11 insertions, 14 deletions
diff --git a/activerecord/lib/active_record/associations/association_scope.rb b/activerecord/lib/active_record/associations/association_scope.rb
index 48288496c4..5268fb2ac8 100644
--- a/activerecord/lib/active_record/associations/association_scope.rb
+++ b/activerecord/lib/active_record/associations/association_scope.rb
@@ -34,7 +34,7 @@ module ActiveRecord
scope = klass.unscoped
owner = association.owner
alias_tracker = AliasTracker.empty connection
- chain = get_chain(reflection, association)
+ chain = get_chain(reflection, association, alias_tracker)
scope.extending! Array(reflection.options[:extend])
add_constraints(scope, owner, klass, reflection, alias_tracker, chain)
@@ -62,13 +62,6 @@ module ActiveRecord
end
private
-
- def construct_tables(chain, alias_tracker, name)
- chain.map do |reflection|
- reflection.alias_name(name, alias_tracker)
- end
- end
-
def join(table, constraint)
table.create_join(table, table.create_on(constraint), join_type)
end
@@ -176,16 +169,20 @@ module ActiveRecord
end
end
- def get_chain(reflection, association)
- chain = reflection.chain.map { |reflection|
- ReflectionProxy.new(reflection)
+ def get_chain(refl, association, tracker)
+ name = refl.name
+ runtime_reflection = RuntimeReflection.new(refl, association)
+ runtime_reflection.alias_name(name, tracker)
+ chain = [runtime_reflection]
+ chain.concat refl.chain.drop(1).map { |reflection|
+ proxy = ReflectionProxy.new(reflection)
+ proxy.alias_name(name, tracker)
+ proxy
}
- chain[0] = RuntimeReflection.new(reflection, association)
chain
end
def add_constraints(scope, owner, assoc_klass, refl, tracker, chain)
- construct_tables(chain, tracker, refl.name)
owner_reflection = chain.last
table = owner_reflection.alias_name(refl.name, tracker)
scope = last_chain_scope(scope, table, owner_reflection, owner, tracker, assoc_klass)
@@ -209,7 +206,7 @@ module ActiveRecord
scope.merge! item.except(:where, :includes, :bind)
end
- if i == 0
+ if reflection == chain.first
scope.includes! item.includes_values
end