diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-08 15:35:55 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-08 15:35:55 -0700 |
commit | c04a8192fdc78b5c24e33e16dab785e2b097009d (patch) | |
tree | dd76f48625e3a965aa637cbce432720ba121ceba | |
parent | d0be8a04804fc6e7aa9fa762e4610760891fd5d1 (diff) | |
download | rails-c04a8192fdc78b5c24e33e16dab785e2b097009d.tar.gz rails-c04a8192fdc78b5c24e33e16dab785e2b097009d.tar.bz2 rails-c04a8192fdc78b5c24e33e16dab785e2b097009d.zip |
associations is always a hash
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency.rb | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index dbea122694..227e967c95 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -134,29 +134,23 @@ module ActiveRecord end def remove_duplicate_results!(base, records, associations) - case associations - when Symbol - reflection = base.reflections[associations] + associations.each_key do |name| + reflection = base.reflections[name] remove_uniq_by_reflection(reflection, records) - when Hash - associations.each_key do |name| - reflection = base.reflections[name] - remove_uniq_by_reflection(reflection, records) - - parent_records = [] - records.each do |record| - if descendant = record.send(reflection.name) - if reflection.collection? - parent_records.concat descendant.target.uniq - else - parent_records << descendant - end + + parent_records = [] + records.each do |record| + if descendant = record.send(reflection.name) + if reflection.collection? + parent_records.concat descendant.target.uniq + else + parent_records << descendant end end + end - unless parent_records.empty? - remove_duplicate_results!(reflection.klass, parent_records, associations[name]) - end + unless parent_records.empty? + remove_duplicate_results!(reflection.klass, parent_records, associations[name]) end end end |