aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/enum.rb
diff options
context:
space:
mode:
authorGodfrey Chan <godfreykfc@gmail.com>2015-02-13 16:18:22 -0800
committerGodfrey Chan <godfreykfc@gmail.com>2015-02-13 16:18:26 -0800
commitae33aea62cd1d3cf489a9335fadc30d1c11e0dc4 (patch)
tree352706eb141bd56dc299df0fc9cfc5a8ca70b46f /activerecord/lib/active_record/enum.rb
parent62133326df3c7edff67a2e57ae32c95bf6e8a818 (diff)
downloadrails-ae33aea62cd1d3cf489a9335fadc30d1c11e0dc4.tar.gz
rails-ae33aea62cd1d3cf489a9335fadc30d1c11e0dc4.tar.bz2
rails-ae33aea62cd1d3cf489a9335fadc30d1c11e0dc4.zip
Enums should be referred to by symbols
Also updated the documentation about the new ability to query them normally, and added test to make sure they work!
Diffstat (limited to 'activerecord/lib/active_record/enum.rb')
-rw-r--r--activerecord/lib/active_record/enum.rb11
1 files changed, 6 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/enum.rb b/activerecord/lib/active_record/enum.rb
index 3086f13f96..5cb80d185b 100644
--- a/activerecord/lib/active_record/enum.rb
+++ b/activerecord/lib/active_record/enum.rb
@@ -32,6 +32,12 @@ module ActiveRecord
# Conversation.active
# Conversation.archived
#
+ # Of course, you can also query them directly if the scopes doesn't fit your
+ # needs:
+ #
+ # Conversation.where(status: [:active, :archived])
+ # Conversation.where("status <> ?", :active)
+ #
# You can set the default value from the database declaration, like:
#
# create_table :conversations do |t|
@@ -63,11 +69,6 @@ module ActiveRecord
#
# Conversation.statuses # => { "active" => 0, "archived" => 1 }
#
- # Use that class method when you need to know the ordinal value of an enum:
- #
- # Conversation.where("status <> ?", Conversation.statuses[:archived])
- #
- # Where conditions on an enum attribute must use the ordinal value of an enum.
module Enum
def self.extended(base) # :nodoc:
base.class_attribute(:defined_enums)