ActiveRecord::Scoping::Default::ClassMethods

module ActiveRecord::Scoping::Default::ClassMethods

Public Instance Methods

unscoped() { || ... } Show source

Returns a scope for the model without the previously set scopes.

class Post < ActiveRecord::Base
  def self.default_scope
    where(published: true)
  end
end

Post.all                                  # Fires "SELECT * FROM posts WHERE published = true"
Post.unscoped.all                         # Fires "SELECT * FROM posts"
Post.where(published: false).unscoped.