diff options
author | José Valim <jose.valim@gmail.com> | 2010-08-02 17:20:17 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-08-02 17:20:17 +0200 |
commit | 9effe3cc18182abbcf0a8b01635a34ca77b67e02 (patch) | |
tree | 2ac911e708f53762bd6d8119ffb28bc108d5618c | |
parent | 009aa8825b6932b006f005ac351b82ad8100d7f1 (diff) | |
download | rails-9effe3cc18182abbcf0a8b01635a34ca77b67e02.tar.gz rails-9effe3cc18182abbcf0a8b01635a34ca77b67e02.tar.bz2 rails-9effe3cc18182abbcf0a8b01635a34ca77b67e02.zip |
Remove duplicated logic.
-rw-r--r-- | activerecord/lib/active_record/associations.rb | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 9cd3b9662f..fdc203e298 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1805,9 +1805,7 @@ module ActiveRecord case associations when Symbol, String reflection = base.reflections[associations] - if reflection && reflection.collection? - records.each { |record| record.send(reflection.name).target.uniq! } - end + remove_uniq_by_reflection(reflection, records) when Array associations.each do |association| remove_duplicate_results!(base, records, association) @@ -1815,10 +1813,7 @@ module ActiveRecord when Hash associations.keys.each do |name| reflection = base.reflections[name] - - if records.any? && reflection.options && reflection.options[:uniq] - records.each { |record| record.send(reflection.name).target.uniq! } - end + remove_uniq_by_reflection(reflection, records) parent_records = [] records.each do |record| @@ -1837,6 +1832,7 @@ module ActiveRecord end protected + def build(associations, parent = nil, join_class = Arel::InnerJoin) parent ||= @joins.last case associations @@ -1859,6 +1855,12 @@ module ActiveRecord end end + def remove_uniq_by_reflection(reflection, records) + if reflection && reflection.collection? + records.each { |record| record.send(reflection.name).target.uniq! } + end + end + def build_join_association(reflection, parent) JoinAssociation.new(reflection, self, parent) end |