lib/searchlogic/named_scopes/or_conditions.rb in searchlogic-2.3.13 vs lib/searchlogic/named_scopes/or_conditions.rb in searchlogic-2.3.14

- old
+ new

@@ -121,19 +121,19 @@ scopes_options = scopes.collect { |scope, *args| send(scope, *args).proxy_options } # We're using first scope to determine column's type scope = named_scope_options(scopes.first) column_type = scope.respond_to?(:searchlogic_arg_type) ? scope.searchlogic_arg_type : :string named_scope scopes.join("_or_"), searchlogic_lambda(column_type) { |*args| - merge_scopes_with_or(scopes.collect { |scope| send(scope, *args) }) + merge_scopes_with_or(scopes.collect { |scope| clone.send(scope, *args) }) } end def merge_scopes_with_or(scopes) - scopes_options = scopes.collect { |scope| scope.proxy_options } + scopes_options = scopes.collect { |scope| scope.scope(:find) } conditions = scopes_options.reject { |o| o[:conditions].nil? }.collect { |o| sanitize_sql(o[:conditions]) } scope = scopes_options.inject(scoped({})) { |current_scope, options| current_scope.scoped(options) } options = scope.scope(:find) - options.delete(:readonly) unless scope.proxy_options.key?(:readonly) + options.delete(:readonly) unless scopes.any? { |scope| scope.proxy_options.key?(:readonly) } options.merge(:conditions => "(" + conditions.join(") OR (") + ")") end end end end