Permalink
Browse files

Fix bug where association conditions were being transfered as a raw h…

…ash, thus enforcing the conditions on the wrong model. The conditions should be sanitized in their respective model first
  • Loading branch information...
1 parent 51b3a2f commit 8aa163ca5d58d38e4213d0aacc5449066aa1b5ee @binarylogic committed Jan 22, 2010
@@ -91,6 +91,8 @@ def arity_args(arity)
def prepare_named_scope_options(options, association)
options.delete(:readonly) # AR likes to set :readonly to true when using the :joins option, we don't want that
+ options[:conditions] = sanitize_sql_for_conditions(options[:conditions]) if options[:conditions].is_a?(Hash)
+
if options[:joins].is_a?(String) || array_of_strings?(options[:joins])
options[:joins] = [inner_joins(association.name), options[:joins]].flatten
else
@@ -137,5 +137,9 @@
user = company.users.create(:company_id => company.id)
company.users.company_id_eq(company.id).should == [user]
end
-
+
+ it "should sanitize the scope on a foreign model instead of passing the raw options back to the original" do
+ Company.named_scope(:users_count_10, :conditions => {:users_count => 10})
+ User.company_users_count_10.proxy_options.should == {:conditions => "\"users\".\"users_count\" = 10", :joins => :company}
+ end
end

0 comments on commit 8aa163c

Please sign in to comment.