From d8bd19f6abd1f8cb344ff5c77971a357c4f5b3ec Mon Sep 17 00:00:00 2001 From: Andrew White Date: Tue, 24 May 2011 07:21:32 +0100 Subject: Ignore :includes on through associations --- activerecord/test/cases/associations/eager_test.rb | 6 ++++++ activerecord/test/models/author.rb | 3 +++ activerecord/test/models/post.rb | 6 ++++++ 3 files changed, 15 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index 3e92a77830..ea186be9dd 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -448,6 +448,12 @@ class EagerAssociationTest < ActiveRecord::TestCase assert_equal post_tags, eager_post_tags end + def test_eager_with_has_many_through_join_model_ignores_default_includes + assert_nothing_raised do + authors(:david).comments_on_posts_with_default_include.to_a + end + 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 diff --git a/activerecord/test/models/author.rb b/activerecord/test/models/author.rb index e0cbc44265..23db5650d4 100644 --- a/activerecord/test/models/author.rb +++ b/activerecord/test/models/author.rb @@ -138,6 +138,9 @@ class Author < ActiveRecord::Base has_many :misc_post_first_blue_tags_2, :through => :posts, :source => :first_blue_tags_2, :conditions => { :posts => { :title => ['misc post by bob', 'misc post by mary'] } } + has_many :posts_with_default_include, :class_name => 'PostWithDefaultInclude' + has_many :comments_on_posts_with_default_include, :through => :posts_with_default_include, :source => :comments + scope :relation_include_posts, includes(:posts) scope :relation_include_tags, includes(:tags) diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb index 80296032bb..f2ab7b053e 100644 --- a/activerecord/test/models/post.rb +++ b/activerecord/test/models/post.rb @@ -162,3 +162,9 @@ class FirstPost < ActiveRecord::Base has_many :comments, :foreign_key => :post_id has_one :comment, :foreign_key => :post_id end + +class PostWithDefaultInclude < ActiveRecord::Base + self.table_name = 'posts' + default_scope includes(:comments) + has_many :comments, :foreign_key => :post_id +end \ No newline at end of file -- cgit v1.2.3