Method: Mongoid::Scopable::ClassMethods#unscoped

Defined in:
lib/mongoid/scopable.rb

#unscopedCriteria | Object

Note:

This will force the default scope, as well as any scope applied using .with_scope, to be removed.

Get the criteria without any scoping applied.

Examples:

Get the unscoped criteria.

Band.unscoped

Yield to block with no scoping.

Band.unscoped do
  Band.where(name: "Depeche Mode")
end

Returns:

  • (Criteria | Object)

    The unscoped criteria or result of the block.



177
178
179
180
181
182
183
184
185
186
187
# File 'lib/mongoid/scopable.rb', line 177

def unscoped
  if block_given?
    without_default_scope do
      with_scope(nil) do
        yield(self)
      end
    end
  else
    queryable.unscoped
  end
end