提交 66e97c34 编写于 作者: R Rick Olson

Ensure that the :uniq option for has_many :through associations retains the order. #10463 [remvee]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8376 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 f67add42
*SVN*
* Ensure that the :uniq option for has_many :through associations retains the order. #10463 [remvee]
* Base.exists? doesn't rescue exceptions to avoid hiding SQL errors. #10458 [Michael Klishin]
* Documentation: Active Record exceptions, destroy_all and delete_all. #10444, #10447 [Michael Klishin]
......
......@@ -148,7 +148,8 @@ def find_target
:include => @reflection.options[:include] || @reflection.source_reflection.options[:include]
)
@reflection.options[:uniq] ? records.to_set.to_a : records
records.uniq! if @reflection.options[:uniq]
records
end
# Construct attributes for associate pointing to owner.
......
......@@ -539,6 +539,12 @@ def test_has_many_through_sum_uses_calculations
def test_has_many_through_has_many_with_sti
assert_equal [comments(:does_it_hurt)], authors(:david).special_post_comments
end
def test_uniq_has_many_through_should_retain_order
comment_ids = authors(:david).comments.map(&:id)
assert_equal comment_ids.sort, authors(:david).ordered_uniq_comments.map(&:id)
assert_equal comment_ids.sort.reverse, authors(:david).ordered_uniq_comments_desc.map(&:id)
end
private
# create dynamic Post models to allow different dependency options
......
......@@ -18,6 +18,8 @@ def testing_proxy_target
has_many :comments_desc, :through => :posts, :source => :comments, :order => 'comments.id DESC'
has_many :limited_comments, :through => :posts, :source => :comments, :limit => 1
has_many :funky_comments, :through => :posts, :source => :comments
has_many :ordered_uniq_comments, :through => :posts, :source => :comments, :uniq => true, :order => 'comments.id'
has_many :ordered_uniq_comments_desc, :through => :posts, :source => :comments, :uniq => true, :order => 'comments.id DESC'
has_many :special_posts
has_many :special_post_comments, :through => :special_posts, :source => :comments
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册