aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/enum.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2013-11-02 18:32:08 -0700
committerDavid Heinemeier Hansson <david@loudthinking.com>2013-11-02 18:32:08 -0700
commitfe9773414a29317ac8fa6c0c911bb88eb2819f40 (patch)
tree084df91c0a38d6c3355907976b16aee54a1b6bf9 /activerecord/lib/active_record/enum.rb
parent0342335473ec1b9977e26089c28d7135ce98d254 (diff)
downloadrails-fe9773414a29317ac8fa6c0c911bb88eb2819f40.tar.gz
rails-fe9773414a29317ac8fa6c0c911bb88eb2819f40.tar.bz2
rails-fe9773414a29317ac8fa6c0c911bb88eb2819f40.zip
Move documentation around a bit
Diffstat (limited to 'activerecord/lib/active_record/enum.rb')
-rw-r--r--activerecord/lib/active_record/enum.rb11
1 files changed, 7 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/enum.rb b/activerecord/lib/active_record/enum.rb
index ef7ccb89bd..d6d1a8c9a2 100644
--- a/activerecord/lib/active_record/enum.rb
+++ b/activerecord/lib/active_record/enum.rb
@@ -2,10 +2,7 @@ module ActiveRecord
# 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]
- #
- # # same but with explicit mapping
- # enum status: {active: 0, archived: 1}
+ # enum status: [ :active, :archived ]
# end
#
# Conversation::STATUS # => { active: 0, archived: 1 }
@@ -30,6 +27,12 @@ module ActiveRecord
# end
#
# Good practice is to let the first declared status be the default.
+ #
+ # Finally, it's also possible to explicitly map the relation between attribute and database integer:
+ #
+ # class Conversation < ActiveRecord::Base
+ # enum status: { active: 0, archived: 1 }
+ # end
module Enum
def enum(definitions)
definitions.each do |name, values|