1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #39895 from abhaynikam/document_default_enum_option

Added documentation for _default option added to ActiveRecord::Enum [ci skip]
This commit is contained in:
Ryuta Kamizono 2020-07-22 17:51:31 +09:00 committed by GitHub
commit 98ddee2b6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -47,13 +47,14 @@ module ActiveRecord
# enum status: [ :active, :archived ], _scopes: false
# end
#
# You can set the default value from the database declaration, like:
# You can set the default enum value by setting +:_default+, like:
#
# create_table :conversations do |t|
# t.column :status, :integer, default: 0
# class Conversation < ActiveRecord::Base
# enum status: [ :active, :archived ], _default: "active"
# end
#
# Good practice is to let the first declared status be the default.
# conversation = Conversation.new
# conversation.status # => "active"
#
# Finally, it's also possible to explicitly map the relation between attribute and
# database integer with a hash: