method

unscoped

rails latest stable - Class: ActiveRecord::Base

Method deprecated or moved

This method is deprecated or moved on the latest stable version. The last existing version (v3.1.0) is shown here.

unscoped()
public

Returns a scope for this class without taking into account the default_scope.

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"

This method also accepts a block meaning that all queries inside the block will not use the default_scope:

Post.unscoped {
  Post.limit(10) # Fires "SELECT * FROM posts LIMIT 10"
}

It is recommended to use block form of unscoped because chaining unscoped with scope does not work. Assuming that published is a scope following two statements are same.

Post.unscoped.published Post.published