diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-08 16:06:29 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-08 16:25:43 -0700 |
commit | d6ce327502b4449110ecc9939c201e44ae64756d (patch) | |
tree | 2b0b7fcfac98a51aeabd27aac3b24a51f10272d1 | |
parent | 40ce6ab5f157fd1c37f46277c645ac5e20830191 (diff) | |
download | rails-d6ce327502b4449110ecc9939c201e44ae64756d.tar.gz rails-d6ce327502b4449110ecc9939c201e44ae64756d.tar.bz2 rails-d6ce327502b4449110ecc9939c201e44ae64756d.zip |
stop looking up the reflection multiple times
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency.rb | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index 4d32fb8571..dace5503e5 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -68,10 +68,9 @@ module ActiveRecord associations.reject { |association| join_assocs.detect { |a| association == a } }.each { |association| - name = association.reflection.name join_part = find_parent_part(association.parent) || base type = association.join_type - find_or_build_scalar name, join_part, type + find_or_build_scalar association.reflection, join_part, type } self end @@ -181,14 +180,14 @@ module ActiveRecord end def build(associations, parent, join_type) - associations.each do |left, right| - join_association = find_or_build_scalar left, parent, join_type + associations.each do |name, right| + reflection = find_reflection parent.base_klass, name + join_association = find_or_build_scalar reflection, parent, join_type build right, join_association, join_type end end - def find_or_build_scalar(name, parent, join_type) - reflection = find_reflection parent.base_klass, name + def find_or_build_scalar(reflection, parent, join_type) unless join_association = find_join_association(reflection, parent) join_association = build_join_association(reflection, parent, join_type) @join_parts << join_association |