From d5ab292ed655e5eaea0b0e13ef6b24d4569b95b7 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 8 Oct 2013 14:25:41 -0700 Subject: we know the keys are scalars, so avoid some typechecking --- .../active_record/associations/join_dependency.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index aa61487285..74cbb95137 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -152,20 +152,14 @@ module ActiveRecord def build(associations, parent, join_type) case associations when Symbol, String - reflection = find_reflection parent.base_klass, associations - unless join_association = find_join_association(reflection, parent) - @reflections << reflection - join_association = build_join_association(reflection, parent, join_type) - @join_parts << join_association - end - join_association + find_or_build_scalar associations, parent, join_type when Array associations.each do |association| build(association, parent, join_type) end when Hash associations.each do |left, right| - join_association = build(left, parent, join_type) + join_association = find_or_build_scalar left, parent, join_type build(right, join_association, join_type) end else @@ -173,6 +167,16 @@ module ActiveRecord end end + def find_or_build_scalar(name, parent, join_type) + reflection = find_reflection parent.base_klass, name + unless join_association = find_join_association(reflection, parent) + @reflections << reflection + join_association = build_join_association(reflection, parent, join_type) + @join_parts << join_association + end + join_association + end + def find_join_association(reflection, parent) join_associations.detect { |j| j.reflection == reflection && j.parent == parent -- cgit v1.2.3