diff --git a/activerecord/lib/active_record/enum.rb b/activerecord/lib/active_record/enum.rb index 1afbfb1977a23bb7e89267d9e744172b533ef2a9..470e0b5d29ab3d105eb502a637eb9378ccc0411c 100644 --- a/activerecord/lib/active_record/enum.rb +++ b/activerecord/lib/active_record/enum.rb @@ -36,6 +36,7 @@ module ActiveRecord # needs: # # Conversation.where(status: [:active, :archived]) + # Conversation.where.not(status: :active) # # You can set the default value from the database declaration, like: # @@ -69,9 +70,8 @@ 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: + # Use that class method when you need to know the ordinal value of an enum. + # For example, you can use that when manually building SQL strings: # # Conversation.where("status <> ?", Conversation.statuses[:archived]) # diff --git a/activerecord/test/cases/enum_test.rb b/activerecord/test/cases/enum_test.rb index 025e39c02df7ec93636fee3d10fd2947a3b30ed9..e70d492efda28570ef40512cf93083e910885f18 100644 --- a/activerecord/test/cases/enum_test.rb +++ b/activerecord/test/cases/enum_test.rb @@ -42,6 +42,8 @@ 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.not(status: :proposed).first + assert_equal @book, Book.where.not(status: :written).first end test "find via where with strings" do @@ -49,6 +51,8 @@ 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.not(status: "proposed").first + assert_equal @book, Book.where.not(status: "written").first end test "build from scope" do