Skip to content
Browse files

* Split out merging scopes with or into a convenient method.

  • Loading branch information...
1 parent cdd01db commit 357874cc713042f850e34cecd89ecfdaaa375208 @binarylogic committed Sep 2, 2009
Showing with 18 additions and 4 deletions.
  1. +5 −1 CHANGELOG.rdoc
  2. +13 −3 lib/searchlogic/named_scopes/or_conditions.rb
View
6 CHANGELOG.rdoc
@@ -1,4 +1,8 @@
-== 2.3.2 relased 2009-08-26
+== 2.3.3 released 2009-09-02
+
+* Split out merging scopes with 'or' into a convenient method.
+
+== 2.3.2 released 2009-08-26
* Add in scope_procedure as an alias for alias_scope.
* Fixed bug with not_blank condition.
View
16 lib/searchlogic/named_scopes/or_conditions.rb
@@ -96,11 +96,21 @@ def interpolate_or_conditions(parts)
def create_or_condition(scopes, args)
named_scope scopes.join("_or_"), lambda { |*args|
- scopes_options = scopes.collect { |scope| send(scope, *args).proxy_options }
- conditions = scopes_options.reject { |o| o[:conditions].nil? }.collect { |o| sanitize_sql(o[:conditions]) }
- scopes.inject(scoped({})) { |scope, scope_name| scope.send(scope_name, *args) }.scope(:find).merge(:conditions => "(" + conditions.join(") OR (") + ")")
+ merge_scopes_with_or(scopes.collect { |scope| [scope, *args] })
}
end
+
+ def merge_scopes_with_or(scopes)
+ scopes_options = scopes.collect { |scope, *args| send(scope, *args).proxy_options }
+ conditions = scopes_options.reject { |o| o[:conditions].nil? }.collect { |o| sanitize_sql(o[:conditions]) }
+
+ scope = scopes.inject(scoped({})) do |scope, info|
+ scope_name, *args = info
+ scope.send(scope_name, *args)
+ end
+
+ scope.scope(:find).merge(:conditions => "(" + conditions.join(") OR (") + ")")
+ end
end
end
end

0 comments on commit 357874c

Please sign in to comment.
Something went wrong with that request. Please try again.