Permalink
Browse files

Fix bug for deep delegation in polymorphic relationships

  • Loading branch information...
1 parent f8da42b commit 9436fd344c62dedfcc15e6583def3b5a3a911c90 @binarylogic binarylogic committed Jan 23, 2010
@@ -114,7 +114,7 @@ def prepare_named_scope_options(options, association, poly_class = nil)
if options[:joins].is_a?(String) || array_of_strings?(options[:joins])
options[:joins] = [poly_class ? poly_join : inner_joins(association.name), options[:joins]].flatten
elsif poly_class
- options[:joins] = options[:joins].blank? ? poly_join : [poly_join, inner_joins(options[:joins])]
+ options[:joins] = options[:joins].blank? ? poly_join : ([poly_join] + klass.inner_joins(options[:joins]))
else
options[:joins] = options[:joins].blank? ? association.name : {association.name => options[:joins]}
end
@@ -143,10 +143,17 @@
User.company_users_count_10.proxy_options.should == {:conditions => "\"companies\".\"users_count\" = 10", :joins => :company}
end
- it "should polymorph" do
+ it "should delegate to polymorphic relationships" do
Audit.auditable_user_type_name_like("ben").proxy_options.should == {
:conditions => ["users.name LIKE ?", "%ben%"],
:joins => "INNER JOIN \"users\" ON \"users\".id = \"audits\".auditable_id AND \"audits\".auditable_type = 'User'"
}
end
+
+ it "should deep delegate to polymorphic relationships" do
+ Audit.auditable_user_type_company_name_like("company").proxy_options.should == {
+ :conditions => ["companies.name LIKE ?", "%company%"],
+ :joins => ["INNER JOIN \"users\" ON \"users\".id = \"audits\".auditable_id AND \"audits\".auditable_type = 'User'", " INNER JOIN \"companies\" ON \"companies\".id = \"users\".company_id "]
+ }
+ end
end

0 comments on commit 9436fd3

Please sign in to comment.