diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-08 14:25:41 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-08 14:25:41 -0700 |
commit | d5ab292ed655e5eaea0b0e13ef6b24d4569b95b7 (patch) | |
tree | befd638ccec03f5d5fec8fd6514994ccb082a517 /activerecord/lib/active_record | |
parent | db5a5eaeecaabc8959e031fcd831a584ab209041 (diff) | |
download | rails-d5ab292ed655e5eaea0b0e13ef6b24d4569b95b7.tar.gz rails-d5ab292ed655e5eaea0b0e13ef6b24d4569b95b7.tar.bz2 rails-d5ab292ed655e5eaea0b0e13ef6b24d4569b95b7.zip |
we know the keys are scalars, so avoid some typechecking
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency.rb | 20 |
1 files 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 |