aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2008-03-26 15:40:57 +0000
committerRick Olson <technoweenie@gmail.com>2008-03-26 15:40:57 +0000
commitc366515abdecf750adfba574be89e8ec43c8553e (patch)
tree4fc55c98b920a7068572d79f3da5328ec6685628 /activerecord/lib
parent1648208ab09277467220efc92a532994024eea78 (diff)
downloadrails-c366515abdecf750adfba574be89e8ec43c8553e.tar.gz
rails-c366515abdecf750adfba574be89e8ec43c8553e.tar.bz2
rails-c366515abdecf750adfba574be89e8ec43c8553e.zip
Fix issue where the :uniq option of a has_many :through association is ignored when find(:all) is called. Closes #9407 [cavalle]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9096 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/has_many_through_association.rb8
1 files changed, 3 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb
index 700a4bf89c..083646f793 100644
--- a/activerecord/lib/active_record/associations/has_many_through_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -153,7 +153,7 @@ module ActiveRecord
end
def find_target
- records = @reflection.klass.find(:all,
+ @reflection.klass.find(:all,
:select => construct_select,
:conditions => construct_conditions,
:from => construct_from,
@@ -164,9 +164,6 @@ module ActiveRecord
:readonly => @reflection.options[:readonly],
:include => @reflection.options[:include] || @reflection.source_reflection.options[:include]
)
-
- records.uniq! if @reflection.options[:uniq]
- records
end
# Construct attributes for associate pointing to owner.
@@ -215,7 +212,8 @@ module ActiveRecord
end
def construct_select(custom_select = nil)
- selected = custom_select || @reflection.options[:select] || "#{@reflection.quoted_table_name}.*"
+ distinct = "DISTINCT " if @reflection.options[:uniq]
+ selected = custom_select || @reflection.options[:select] || "#{distinct}#{@reflection.quoted_table_name}.*"
end
def construct_joins(custom_joins = nil)