class method
self.default_scope
Ruby on Rails 3.0.20
Since v2.3.18 Last seen in v3.1.12Signature
self.default_scope(options = {})
Sets the default options for the model. The format of the options argument is the same as in find.
class Person < ActiveRecord::Base default_scope order('last_name, first_name') end
default_scope is also applied while creating/building a record. It is not applied while updating a record.
class Article < ActiveRecord::Base default_scope where(:published => true) end Article.new.published # => true Article.create.published # => true
Parameters
-
optionsopt = {}
Source
# File activerecord/lib/active_record/base.rb, line 1172
def default_scope(options = {})
reset_scoped_methods
self.default_scoping << construct_finder_arel(options, default_scoping.pop)
end
Defined in activerecord/lib/active_record/base.rb line 1172
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Base