Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix issue 23

  • Loading branch information...
commit a7a2f099d7aa1847250af917e01f0818b56991f1 1 parent ef17d40
@binarylogic authored
View
2  lib/searchlogic/named_scopes/alias_scope.rb
@@ -33,7 +33,7 @@ module AliasScope
# is a safe method.
def alias_scope(name, options = nil)
alias_scopes[name.to_sym] = options
- (class << self; self end).instance_eval do
+ (class << self; self; end).instance_eval do
define_method name do |*args|
case options
when Symbol
View
26 lib/searchlogic/named_scopes/or_conditions.rb
@@ -101,20 +101,20 @@ def interpolate_or_conditions(parts)
end
def full_association_path(part, last_condition, given_assoc)
- path = [given_assoc.name]
- part.sub!(/^#{given_assoc.name}_/, "")
- klass = self
- while klass = klass.send(:reflect_on_association, given_assoc.name)
- klass = klass.klass
- if details = klass.send(:association_condition_details, part, last_condition)
- path << details[:association]
- part = details[:condition]
- given_assoc = details[:association]
- elsif details = klass.send(:condition_details, part)
- return { :path => path, :column => details[:column], :condition => details[:condition] }
- end
+ path = [given_assoc.name]
+ part.sub!(/^#{given_assoc.name}_/, "")
+ klass = self
+ while klass = klass.send(:reflect_on_association, given_assoc.name)
+ klass = klass.klass
+ if details = klass.send(:association_condition_details, part, last_condition)
+ path << details[:association].name
+ part = details[:condition]
+ given_assoc = details[:association]
+ elsif details = klass.send(:condition_details, part)
+ return { :path => path, :column => details[:column], :condition => details[:condition] }
end
- { :path => path, :column => part, :condition => last_condition }
+ end
+ {:path => path, :column => part, :condition => last_condition}
end
def create_or_condition(scopes)
View
1  spec/searchlogic/named_scopes/or_conditions_spec.rb
@@ -44,6 +44,7 @@
User.name_or_company_name_like("ben").proxy_options.should == {:joins => :company, :conditions => "(users.name LIKE '%ben%') OR (companies.name LIKE '%ben%')"}
User.company_name_or_name_like("ben").proxy_options.should == {:joins => :company, :conditions => "(companies.name LIKE '%ben%') OR (users.name LIKE '%ben%')"}
User.company_name_or_company_description_like("ben").proxy_options.should == {:joins =>[:company], :conditions => "(companies.name LIKE '%ben%') OR (companies.description LIKE '%ben%')"}
+ Cart.user_company_name_or_user_company_name_like("ben").proxy_options.should == {:joins => {:user=>:company}, :conditions => "(companies.name LIKE '%ben%') OR (companies.name LIKE '%ben%')"}
end
it "should not get confused by the 'or' in find_or_create_by_* methods" do
Please sign in to comment.
Something went wrong with that request. Please try again.