Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix bug for deep delegation in polymorphic relationships

  • Loading branch information...
commit 9436fd344c62dedfcc15e6583def3b5a3a911c90 1 parent f8da42b
@binarylogic authored
View
2  lib/searchlogic/named_scopes/association_conditions.rb
@@ -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
View
9 spec/named_scopes/association_conditions_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.