Skip to content
This repository
Browse code

Ignore :includes on through associations

  • Loading branch information...
commit d8bd19f6abd1f8cb344ff5c77971a357c4f5b3ec 1 parent a47a65f
Andrew White authored
2  activerecord/lib/active_record/associations/through_association.rb
@@ -16,7 +16,7 @@ def target_scope
16 16
           chain[1..-1].each do |reflection|
17 17
             scope = scope.merge(
18 18
               reflection.klass.scoped.with_default_scope.
19  
-                except(:select, :create_with)
  19
+                except(:select, :create_with, :includes)
20 20
             )
21 21
           end
22 22
           scope
6  activerecord/test/cases/associations/eager_test.rb
@@ -448,6 +448,12 @@ def test_eager_with_has_many_through_with_conditions_join_model_with_include
448 448
     assert_equal post_tags, eager_post_tags
449 449
   end
450 450
 
  451
+  def test_eager_with_has_many_through_join_model_ignores_default_includes
  452
+    assert_nothing_raised do
  453
+      authors(:david).comments_on_posts_with_default_include.to_a
  454
+    end
  455
+  end
  456
+
451 457
   def test_eager_with_has_many_and_limit
452 458
     posts = Post.find(:all, :order => 'posts.id asc', :include => [ :author, :comments ], :limit => 2)
453 459
     assert_equal 2, posts.size
3  activerecord/test/models/author.rb
@@ -138,6 +138,9 @@ def testing_proxy_target
138 138
   has_many :misc_post_first_blue_tags_2, :through => :posts, :source => :first_blue_tags_2,
139 139
            :conditions => { :posts => { :title => ['misc post by bob', 'misc post by mary'] } }
140 140
 
  141
+  has_many :posts_with_default_include, :class_name => 'PostWithDefaultInclude'
  142
+  has_many :comments_on_posts_with_default_include, :through => :posts_with_default_include, :source => :comments
  143
+
141 144
   scope :relation_include_posts, includes(:posts)
142 145
   scope :relation_include_tags, includes(:tags)
143 146
 
6  activerecord/test/models/post.rb
@@ -162,3 +162,9 @@ class FirstPost < ActiveRecord::Base
162 162
   has_many :comments, :foreign_key => :post_id
163 163
   has_one  :comment,  :foreign_key => :post_id
164 164
 end
  165
+
  166
+class PostWithDefaultInclude < ActiveRecord::Base
  167
+  self.table_name = 'posts'
  168
+  default_scope includes(:comments)
  169
+  has_many :comments, :foreign_key => :post_id
  170
+end

0 notes on commit d8bd19f

Please sign in to comment.
Something went wrong with that request. Please try again.