diff options
author | Michael Koziarski <michael@koziarski.com> | 2007-08-16 04:36:55 +0000 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2007-08-16 04:36:55 +0000 |
commit | 82b244e3ffb55b94597b0562919522625ebfd2d3 (patch) | |
tree | 414af9327b68002ad43af344ce6af46bbaa2acc8 /activerecord/test | |
parent | 4954c77b69fcc6d3e7299682c010f0b7b44c54c3 (diff) | |
download | rails-82b244e3ffb55b94597b0562919522625ebfd2d3.tar.gz rails-82b244e3ffb55b94597b0562919522625ebfd2d3.tar.bz2 rails-82b244e3ffb55b94597b0562919522625ebfd2d3.zip |
Make sure has_many associations honour :include when counting. Closes #9167 [danger]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7325 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/associations/eager_test.rb | 7 | ||||
-rw-r--r-- | activerecord/test/fixtures/author.rb | 1 |
2 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/test/associations/eager_test.rb b/activerecord/test/associations/eager_test.rb index d48821ce0a..114da92542 100644 --- a/activerecord/test/associations/eager_test.rb +++ b/activerecord/test/associations/eager_test.rb @@ -271,6 +271,13 @@ class EagerAssociationTest < Test::Unit::TestCase assert_not_nil f.account assert_equal companies(:first_firm, :reload).account, f.account end + + def test_eager_with_multi_table_conditional_properly_counts_the_records_when_using_size + author = authors(:david) + posts_with_no_comments = author.posts.select { |post| post.comments.blank? } + assert_equal posts_with_no_comments.size, author.posts_with_no_comments.size + assert_equal posts_with_no_comments, author.posts_with_no_comments + end def test_eager_with_invalid_association_reference assert_raises(ActiveRecord::ConfigurationError, "Association was not found; perhaps you misspelled it? You specified :include => :monkeys") { diff --git a/activerecord/test/fixtures/author.rb b/activerecord/test/fixtures/author.rb index 61ba3c1551..fa710bab9c 100644 --- a/activerecord/test/fixtures/author.rb +++ b/activerecord/test/fixtures/author.rb @@ -25,6 +25,7 @@ class Author < ActiveRecord::Base has_many :hello_posts, :class_name => "Post", :conditions => "posts.body = 'hello'" has_many :hello_post_comments, :through => :hello_posts, :source => :comments + has_many :posts_with_no_comments, :class_name => 'Post', :conditions => 'comments.id is null', :include => :comments has_many :other_posts, :class_name => "Post" has_many :posts_with_callbacks, :class_name => "Post", :before_add => :log_before_adding, |