diff options
author | Robin Dupret <robin.dupret@gmail.com> | 2013-12-30 17:47:11 +0100 |
---|---|---|
committer | Robin Dupret <robin.dupret@gmail.com> | 2014-01-01 17:57:38 +0100 |
commit | 50060e969b422e6cd8f90181ac3d92f915a96f69 (patch) | |
tree | a41cbe3ed7db08200b8ed7a98f369356393bca6d /activerecord/lib | |
parent | 7aebcb67b040bca353cd2e97a468c8ffe4594665 (diff) | |
download | rails-50060e969b422e6cd8f90181ac3d92f915a96f69.tar.gz rails-50060e969b422e6cd8f90181ac3d92f915a96f69.tar.bz2 rails-50060e969b422e6cd8f90181ac3d92f915a96f69.zip |
Improve enum documentation
Add a mention about the automatic generation of scopes based on the
allowed values of the field on the enum documentation.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/enum.rb | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/enum.rb b/activerecord/lib/active_record/enum.rb index aebb061717..c042a2f232 100644 --- a/activerecord/lib/active_record/enum.rb +++ b/activerecord/lib/active_record/enum.rb @@ -1,5 +1,6 @@ module ActiveRecord - # Declare an enum attribute where the values map to integers in the database, but can be queried by name. Example: + # Declare an enum attribute where the values map to integers in the database, + # but can be queried by name. Example: # # class Conversation < ActiveRecord::Base # enum status: [ :active, :archived ] @@ -23,6 +24,10 @@ module ActiveRecord # conversation.status.nil? # => true # conversation.status # => nil # + # Scopes based on the allowed values of the enum field will be provided + # as well. With the above example, it will create an +active+ and +archived+ + # scope. + # # You can set the default value from the database declaration, like: # # create_table :conversations do |t| |