    # File lib/active_record/base.rb, line 901
          def with_scope(method_scoping = {}, action = :merge, &block)
            method_scoping = method_scoping.method_scoping if method_scoping.respond_to?(:method_scoping)

            # Dup first and second level of hash (method and params).
            method_scoping = method_scoping.inject({}) do |hash, (method, params)|
              hash[method] = (params == true) ? params : params.dup
              hash
            end

            method_scoping.assert_valid_keys([ :find, :create ])

            if f = method_scoping[:find]
              f.assert_valid_keys([ :conditions, :joins, :select, :include, :from, :offset, :limit, :order, :readonly, :lock ])
              f[:readonly] = true if !f[:joins].blank? && !f.has_key?(:readonly)
            end

            # Merge scopings
            if action == :merge && current_scoped_methods
              method_scoping = current_scoped_methods.inject(method_scoping) do |hash, (method, params)|
                case hash[method]
                  when Hash
                    if method == :find
                      (hash[method].keys + params.keys).uniq.each do |key|
                        merge = hash[method][key] && params[key] # merge if both scopes have the same key
                        if key == :conditions && merge
                          hash[method][key] = [params[key], hash[method][key]].collect{ |sql| "( %s )" % sanitize_sql(sql) }.join(" AND ")
                        elsif key == :include && merge
                          hash[method][key] = merge_includes(hash[method][key], params[key]).uniq
                        else
                          hash[method][key] = hash[method][key] || params[key]
                        end
                      end
                    else
                      hash[method] = params.merge(hash[method])
                    end
                  else
                    hash[method] = params
                end
                hash
              end
            end

            self.scoped_methods << method_scoping

            begin
              yield
            ensure
              self.scoped_methods.pop
            end
          end