From ae33aea62cd1d3cf489a9335fadc30d1c11e0dc4 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Fri, 13 Feb 2015 16:18:22 -0800 Subject: 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! --- activerecord/lib/active_record/enum.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'activerecord/lib') 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) -- cgit v1.2.3