@@ -1805,20 +1805,15 @@ def remove_duplicate_results!(base, records, associations)
1805
1805
case associations
1806
1806
when Symbol , String
1807
1807
reflection = base . reflections [ associations ]
1808
- if reflection && reflection . collection?
1809
- records . each { |record | record . send ( reflection . name ) . target . uniq! }
1810
- end
1808
+ remove_uniq_by_reflection ( reflection , records )
1811
1809
when Array
1812
1810
associations . each do |association |
1813
1811
remove_duplicate_results! ( base , records , association )
1814
1812
end
1815
1813
when Hash
1816
1814
associations . keys . each do |name |
1817
1815
reflection = base . reflections [ name ]
1818
-
1819
- if records . any? && reflection . options && reflection . options [ :uniq ]
1820
- records . each { |record | record . send ( reflection . name ) . target . uniq! }
1821
- end
1816
+ remove_uniq_by_reflection ( reflection , records )
1822
1817
1823
1818
parent_records = [ ]
1824
1819
records . each do |record |
@@ -1837,6 +1832,7 @@ def remove_duplicate_results!(base, records, associations)
1837
1832
end
1838
1833
1839
1834
protected
1835
+
1840
1836
def build ( associations , parent = nil , join_class = Arel ::InnerJoin )
1841
1837
parent ||= @joins . last
1842
1838
case associations
@@ -1859,6 +1855,12 @@ def build(associations, parent = nil, join_class = Arel::InnerJoin)
1859
1855
end
1860
1856
end
1861
1857
1858
+ def remove_uniq_by_reflection ( reflection , records )
1859
+ if reflection && reflection . collection?
1860
+ records . each { |record | record . send ( reflection . name ) . target . uniq! }
1861
+ end
1862
+ end
1863
+
1862
1864
def build_join_association ( reflection , parent )
1863
1865
JoinAssociation . new ( reflection , self , parent )
1864
1866
end
0 commit comments