mirror of
https://github.com/github/rails.git
synced 2026-01-30 00:38:00 -05:00
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
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* Fix issue where the :uniq option of a has_many :through association is ignored when find(:all) is called. Closes #9407 [cavalle]
|
||||
|
||||
* Fix duplicate table alias error when including an association with a has_many :through association on the same join table. Closes #7310 [cavalle]
|
||||
|
||||
* More efficient association preloading code that compacts a through_records array in a central location. Closes #11427 [danger]
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -41,6 +41,14 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
|
||||
assert_queries(1) { assert_equal 0, author.unique_categorized_posts.count(:title, :conditions => "title is NULL") }
|
||||
assert !authors(:mary).unique_categorized_posts.loaded?
|
||||
end
|
||||
|
||||
def test_has_many_uniq_through_find
|
||||
assert_equal 1, authors(:mary).unique_categorized_posts.find(:all).size
|
||||
end
|
||||
|
||||
def test_has_many_uniq_through_dynamic_find
|
||||
assert_equal 1, authors(:mary).unique_categorized_posts.find_all_by_title("So I was thinking").size
|
||||
end
|
||||
|
||||
def test_polymorphic_has_many
|
||||
assert posts(:welcome).taggings.include?(taggings(:welcome_general))
|
||||
|
||||
Reference in New Issue
Block a user