Method: Mongoid::Scopable::ClassMethods#unscoped

Defined in:
lib/mongoid/scopable.rb

#unscopedCriteria, Object

Note:

This will force the default scope to be removed.

Get the criteria without the default scoping applied.

Examples:

Get the unscoped criteria.

Band.unscoped

Yield to block with no default scoping.

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

Returns:

  • (Criteria, Object)

    The unscoped criteria or result of the block.

Since:

  • 3.0.0



190
191
192
193
194
195
196
197
198
# File 'lib/mongoid/scopable.rb', line 190

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