Method: Mongoid::Criteria::Scopable#with_default_scope

Defined in:
lib/mongoid/criteria/scopable.rb

#with_default_scopeCriteria

Get the criteria with the default scope applied, if the default scope is able to be applied. Cases in which it cannot are: If we are in an unscoped block, if the criteria is already forced unscoped, or the default scope has already been applied.

Examples:

Get the criteria with the default scope.

criteria.with_default_scope

Returns:

  • The criteria.



152
153
154
155
156
157
158
# File 'lib/mongoid/criteria/scopable.rb', line 152

def with_default_scope
  crit = clone
  if klass.default_scopable? && !unscoped? && !scoped?
    crit.apply_default_scope
  end
  crit
end