diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-09 15:08:22 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-09 15:08:22 -0700 |
commit | a64f1ea08cf9ce38a920c247866804e9449ba7da (patch) | |
tree | afc09555d2ce86e44b80db9276e43e0f0a90bff5 /activerecord/lib | |
parent | 4852a05ce66cedfa09a422fa601dd853f2070727 (diff) | |
download | rails-a64f1ea08cf9ce38a920c247866804e9449ba7da.tar.gz rails-a64f1ea08cf9ce38a920c247866804e9449ba7da.tar.bz2 rails-a64f1ea08cf9ce38a920c247866804e9449ba7da.zip |
just skip the join if it's already there
Remove the annoying `find_or_build` stuff.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency.rb | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index 199d28426b..4f30d71b98 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -70,10 +70,13 @@ module ActiveRecord associations.reject { |association| join_assocs.detect { |a| node_cmp association, a } - }.each { |association| - join_node = find_node(association.parent) || @join_root - type = association.join_type - find_or_build_scalar association.reflection, join_node, type + }.each { |join_node| + parent = find_node(join_node.parent) || @join_root + reflection = join_node.reflection + type = join_node.join_type + + next if parent.children.find { |j| j.reflection == reflection } + build_scalar reflection, parent, type } self end @@ -194,16 +197,9 @@ module ActiveRecord end end - 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) - parent.children << join_association - end - join_association - end - - def find_join_association(reflection, parent) - parent.children.find { |j| j.reflection == reflection } + def build_scalar(reflection, parent, join_type) + join_association = build_join_association(reflection, parent, join_type) + parent.children << join_association end def remove_uniq_by_reflection(reflection, records) |