提交 b7982383 编写于 作者: W Will Bryant 提交者: Aaron Patterson

Verify that has_one :through preload respects the :conditions [#2976 state:resolved]

上级 c6db37e6
...@@ -84,6 +84,18 @@ def test_has_one_through_eager_loading_through_polymorphic ...@@ -84,6 +84,18 @@ def test_has_one_through_eager_loading_through_polymorphic
assert_not_nil assert_no_queries {members[0].sponsor_club} assert_not_nil assert_no_queries {members[0].sponsor_club}
end end
def test_has_one_through_with_conditions_eager_loading
# conditions on the through table
assert_equal clubs(:moustache_club), Member.find(@member.id, :include => :favourite_club).favourite_club
memberships(:membership_of_favourite_club).update_attribute(:favourite, false)
assert_equal nil, Member.find(@member.id, :include => :favourite_club).favourite_club
# conditions on the source table
assert_equal clubs(:moustache_club), Member.find(@member.id, :include => :hairy_club).hairy_club
clubs(:moustache_club).update_attribute(:name, "Association of Clean-Shaven Persons")
assert_equal nil, Member.find(@member.id, :include => :hairy_club).hairy_club
end
def test_has_one_through_polymorphic_with_source_type def test_has_one_through_polymorphic_with_source_type
assert_equal members(:groucho), clubs(:moustache_club).sponsored_member assert_equal members(:groucho), clubs(:moustache_club).sponsored_member
end end
......
...@@ -4,6 +4,7 @@ class Member < ActiveRecord::Base ...@@ -4,6 +4,7 @@ class Member < ActiveRecord::Base
has_many :fellow_members, :through => :club, :source => :members has_many :fellow_members, :through => :club, :source => :members
has_one :club, :through => :current_membership has_one :club, :through => :current_membership
has_one :favourite_club, :through => :membership, :conditions => ["memberships.favourite = ?", true], :source => :club has_one :favourite_club, :through => :membership, :conditions => ["memberships.favourite = ?", true], :source => :club
has_one :hairy_club, :through => :membership, :conditions => {:clubs => {:name => "Moustache and Eyebrow Fancier Club"}}, :source => :club
has_one :sponsor, :as => :sponsorable has_one :sponsor, :as => :sponsorable
has_one :sponsor_club, :through => :sponsor has_one :sponsor_club, :through => :sponsor
has_one :member_detail has_one :member_detail
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册