diff options
author | Godfrey Chan <godfreykfc@gmail.com> | 2015-02-13 16:50:08 -0800 |
---|---|---|
committer | Godfrey Chan <godfreykfc@gmail.com> | 2015-02-13 16:50:08 -0800 |
commit | 53f3803b52bfe2f4a8e0550a0c5d9df1865d90cb (patch) | |
tree | 7b028694e2e5602026f0ec9047120f8afbe2beea | |
parent | 58adda34778ef2c874ee86e491d05042b99e6a18 (diff) | |
download | rails-53f3803b52bfe2f4a8e0550a0c5d9df1865d90cb.tar.gz rails-53f3803b52bfe2f4a8e0550a0c5d9df1865d90cb.tar.bz2 rails-53f3803b52bfe2f4a8e0550a0c5d9df1865d90cb.zip |
Partially revert ae33aea
Using enum names in SQL strings doesn't actually work, the test was wrong (fixed
in 3dfd1ba).
-rw-r--r-- | activerecord/lib/active_record/enum.rb | 8 | ||||
-rw-r--r-- | activerecord/test/cases/enum_test.rb | 4 |
2 files changed, 7 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/enum.rb b/activerecord/lib/active_record/enum.rb index 8eaea6c055..442fb3fdc9 100644 --- a/activerecord/lib/active_record/enum.rb +++ b/activerecord/lib/active_record/enum.rb @@ -36,7 +36,6 @@ module ActiveRecord # needs: # # Conversation.where(status: [:active, :archived]) - # Conversation.where("status <> ?", :active) # # You can set the default value from the database declaration, like: # @@ -70,6 +69,13 @@ module ActiveRecord # Conversation.statuses[:active] # => 0 # Conversation.statuses["archived"] # => 1 # + # Use that class method when you need to know the ordinal value of an enum. For + # example, you can use that when manually building a SQL string inside a `where` + # condition: + # + # Conversation.where("status <> ?", Conversation.statuses[:archived]) + # + module Enum def self.extended(base) # :nodoc: base.class_attribute(:defined_enums) diff --git a/activerecord/test/cases/enum_test.rb b/activerecord/test/cases/enum_test.rb index 0cb34b5960..41685cbc39 100644 --- a/activerecord/test/cases/enum_test.rb +++ b/activerecord/test/cases/enum_test.rb @@ -42,8 +42,6 @@ class EnumTest < ActiveRecord::TestCase refute_equal @book, Book.where(status: :written).first assert_equal @book, Book.where(status: [:proposed]).first refute_equal @book, Book.where(status: [:written]).first - refute_equal @book, Book.where("status <> ?", :proposed).first - assert_equal @book, Book.where("status <> ?", :written).first end test "find via where with strings" do @@ -51,8 +49,6 @@ class EnumTest < ActiveRecord::TestCase refute_equal @book, Book.where(status: "written").first assert_equal @book, Book.where(status: ["proposed"]).first refute_equal @book, Book.where(status: ["written"]).first - refute_equal @book, Book.where("status <> ?", "proposed").first - assert_equal @book, Book.where("status <> ?", "written").first end test "build from scope" do |