diff options
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/associations/eager_test.rb | 6 | ||||
-rw-r--r-- | activerecord/test/fixtures/readers.yml | 5 | ||||
-rw-r--r-- | activerecord/test/models/person.rb | 1 | ||||
-rw-r--r-- | activerecord/test/models/post.rb | 2 |
4 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index a4fd71abea..810336684c 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -246,6 +246,12 @@ class EagerAssociationTest < ActiveRecord::TestCase author_posts_without_comments = author.posts.select { |post| post.comments.blank? } assert_equal author_posts_without_comments.size, author.posts.count(:all, :include => :comments, :conditions => 'comments.id is null') end + + def test_eager_count_performed_on_a_has_many_through_association_with_multi_table_conditional + person = people(:michael) + person_posts_without_comments = person.posts.select { |post| post.comments.blank? } + assert_equal person_posts_without_comments.size, person.posts_with_no_comments.count + end def test_eager_with_has_and_belongs_to_many_and_limit posts = Post.find(:all, :include => :categories, :order => "posts.id", :limit => 3) diff --git a/activerecord/test/fixtures/readers.yml b/activerecord/test/fixtures/readers.yml index 6ed73c9ec3..8a6076655b 100644 --- a/activerecord/test/fixtures/readers.yml +++ b/activerecord/test/fixtures/readers.yml @@ -2,3 +2,8 @@ michael_welcome: id: 1 post_id: 1 person_id: 1 + +michael_authorless: + id: 2 + post_id: 3 + person_id: 1
\ No newline at end of file diff --git a/activerecord/test/models/person.rb b/activerecord/test/models/person.rb index 7a9666f4eb..366f9fb708 100644 --- a/activerecord/test/models/person.rb +++ b/activerecord/test/models/person.rb @@ -1,4 +1,5 @@ class Person < ActiveRecord::Base has_many :readers has_many :posts, :through => :readers + has_many :posts_with_no_comments, :through => :readers, :source => :post, :include => :comments, :conditions => 'comments.id is null' end diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb index 176a0ddc1e..7f9d53b34b 100644 --- a/activerecord/test/models/post.rb +++ b/activerecord/test/models/post.rb @@ -25,7 +25,7 @@ class Post < ActiveRecord::Base has_and_belongs_to_many :special_categories, :join_table => "categories_posts", :association_foreign_key => 'category_id' has_many :taggings, :as => :taggable - has_many :tags, :through => :taggings, :include => :tagging do + has_many :tags, :through => :taggings do def add_joins_and_select find :all, :select => 'tags.*, authors.id as author_id', :include => false, :joins => 'left outer join posts on taggings.taggable_id = posts.id left outer join authors on posts.author_id = authors.id' |