Permalink
Browse files

Produced a possible fix, spec test results fail but are "close" - thi…

…s commit is not working and is for illustrative purposes only.
  • Loading branch information...
1 parent 5e13e5a commit b333f67470a4880cf0743e6d151c4f50874afafd n00bish committed with Oct 23, 2009
@@ -77,8 +77,13 @@ def method_missing(name, *args, &block)
end
end
- def condition_details(name)
- if name.to_s =~ /^(#{column_names.join("|")})_(#{(PRIMARY_CONDITIONS + ALIAS_CONDITIONS).join("|")})$/
+ def condition_details(name, *args)
+ if args.size > 0 and !args.first.nil?
+ assoc = reflect_on_association(args.first.to_sym)
+ klass = assoc.klass
+ name.to_s =~ /^(#{klass.column_names.join("|")})_(#{(PRIMARY_CONDITIONS + ALIAS_CONDITIONS).join("|")})$/
+ {:column => $1, :condition => $2}
+ elsif name.to_s =~ /^(#{column_names.join("|")})_(#{(PRIMARY_CONDITIONS + ALIAS_CONDITIONS).join("|")})$/
{:column => $1, :condition => $2}
end
end
@@ -74,8 +74,9 @@ def interpolate_or_conditions(parts)
conditions << "#{details[:column]}_#{details[:condition]}"
last_condition = details[:condition]
elsif association_details = association_condition_details(part, last_condition)
- if details = condition_details(association_details[:condition])
- conditions << "#{association_details[:association]}_#{details[:column]}_#{details[:condition]}"
+ path = full_association_path(part, last_condition).join("_")
+ if details = condition_details(association_details[:condition], path.empty? ? nil : path.to_sym )
+ conditions << "#{path.to_sym}_#{details[:column]}_#{details[:condition]}"
last_condition = details[:condition]
end
elsif local_condition?(part)
@@ -96,6 +97,15 @@ def interpolate_or_conditions(parts)
conditions.reverse
end
+
+ def full_association_path(assoc, last_condition)
+ path = []
+ while details = association_condition_details(assoc, last_condition)
+ path << details[:association]
+ assoc = details[:condition]
+ end
+ path
+ end
def create_or_condition(scopes, args)
named_scope scopes.join("_or_"), lambda { |*args|
@@ -118,4 +128,4 @@ def merge_scopes_with_or(scopes)
end
end
end
-end
+end
@@ -43,6 +43,6 @@
lambda { User.name_or_company_name_like("ben") }.should_not raise_error(Searchlogic::NamedScopes::OrConditions::NoConditionSpecifiedError)
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 (company.description 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%')"}
end
end

0 comments on commit b333f67

Please sign in to comment.