From cdb5132c411db0a330e85ec9d2eb7fe543af7aff Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Sun, 15 Oct 2006 16:37:11 +0000 Subject: Fix has_many :through to add the appropriate conditions when going through an association using STI. Closes #5783. [Jonathan Viney] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5305 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/test/associations/eager_test.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'activerecord/test/associations/eager_test.rb') diff --git a/activerecord/test/associations/eager_test.rb b/activerecord/test/associations/eager_test.rb index d6e795b1fe..909083fd28 100644 --- a/activerecord/test/associations/eager_test.rb +++ b/activerecord/test/associations/eager_test.rb @@ -104,7 +104,7 @@ class EagerAssociationTest < Test::Unit::TestCase end def test_eager_with_has_many_through - posts_with_comments = people(:michael).posts.find(:all, :include => :comments ) + posts_with_comments = people(:michael).posts.find(:all, :include => :comments) posts_with_author = people(:michael).posts.find(:all, :include => :author ) posts_with_comments_and_author = people(:michael).posts.find(:all, :include => [ :comments, :author ]) assert_equal 2, posts_with_comments.inject(0) { |sum, post| sum += post.comments.size } @@ -112,6 +112,21 @@ class EagerAssociationTest < Test::Unit::TestCase assert_equal authors(:david), assert_no_queries { posts_with_comments_and_author.first.author } end + def test_eager_with_has_many_through_an_sti_join_model + author = Author.find(:first, :include => :special_post_comments, :order => 'authors.id') + assert_equal [comments(:does_it_hurt)], assert_no_queries { author.special_post_comments } + end + + def test_eager_with_has_many_through_an_sti_join_model_with_conditions_on_both + author = Author.find(:first, :include => :special_nonexistant_post_comments, :order => 'authors.id') + assert_equal [], author.special_nonexistant_post_comments + end + + def test_eager_with_has_many_through_join_model_with_conditions + assert_equal Author.find(:first, :include => :hello_post_comments).hello_post_comments, + Author.find(:first).hello_post_comments + end + def test_eager_with_has_many_and_limit posts = Post.find(:all, :order => 'posts.id asc', :include => [ :author, :comments ], :limit => 2) assert_equal 2, posts.size -- cgit v1.2.3