Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove duplicated logic.

  • Loading branch information...
commit 9effe3cc18182abbcf0a8b01635a34ca77b67e02 1 parent 009aa88
@josevalim josevalim authored
Showing with 9 additions and 7 deletions.
  1. +9 −7 activerecord/lib/active_record/associations.rb
View
16 activerecord/lib/active_record/associations.rb
@@ -1805,9 +1805,7 @@ def remove_duplicate_results!(base, records, associations)
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 @@ def remove_duplicate_results!(base, records, associations)
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 @@ def remove_duplicate_results!(base, records, associations)
end
protected
+
def build(associations, parent = nil, join_class = Arel::InnerJoin)
parent ||= @joins.last
case associations
@@ -1859,6 +1855,12 @@ def build(associations, parent = nil, join_class = Arel::InnerJoin)
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
Please sign in to comment.
Something went wrong with that request. Please try again.