提交 d8bd19f6 编写于 作者: A Andrew White

Ignore :includes on through associations

上级 a47a65f1
...@@ -16,7 +16,7 @@ def target_scope ...@@ -16,7 +16,7 @@ def target_scope
chain[1..-1].each do |reflection| chain[1..-1].each do |reflection|
scope = scope.merge( scope = scope.merge(
reflection.klass.scoped.with_default_scope. reflection.klass.scoped.with_default_scope.
except(:select, :create_with) except(:select, :create_with, :includes)
) )
end end
scope scope
......
...@@ -448,6 +448,12 @@ def test_eager_with_has_many_through_with_conditions_join_model_with_include ...@@ -448,6 +448,12 @@ def test_eager_with_has_many_through_with_conditions_join_model_with_include
assert_equal post_tags, eager_post_tags assert_equal post_tags, eager_post_tags
end 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 def test_eager_with_has_many_and_limit
posts = Post.find(:all, :order => 'posts.id asc', :include => [ :author, :comments ], :limit => 2) posts = Post.find(:all, :order => 'posts.id asc', :include => [ :author, :comments ], :limit => 2)
assert_equal 2, posts.size assert_equal 2, posts.size
......
...@@ -138,6 +138,9 @@ def testing_proxy_target ...@@ -138,6 +138,9 @@ def testing_proxy_target
has_many :misc_post_first_blue_tags_2, :through => :posts, :source => :first_blue_tags_2, 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'] } } :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_posts, includes(:posts)
scope :relation_include_tags, includes(:tags) scope :relation_include_tags, includes(:tags)
......
...@@ -162,3 +162,9 @@ class FirstPost < ActiveRecord::Base ...@@ -162,3 +162,9 @@ class FirstPost < ActiveRecord::Base
has_many :comments, :foreign_key => :post_id has_many :comments, :foreign_key => :post_id
has_one :comment, :foreign_key => :post_id has_one :comment, :foreign_key => :post_id
end 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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册