aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-01-01 19:17:59 -0200
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-01-01 19:17:59 -0200
commit358abe4524ca0ccaa35d255fb090a269b1df35f0 (patch)
tree6751f6cba1ed4a6ce80f1fd5ef8e56ce1546619a /activerecord/lib
parentf141919974806568f480cf2c670f990322308044 (diff)
parent50060e969b422e6cd8f90181ac3d92f915a96f69 (diff)
downloadrails-358abe4524ca0ccaa35d255fb090a269b1df35f0.tar.gz
rails-358abe4524ca0ccaa35d255fb090a269b1df35f0.tar.bz2
rails-358abe4524ca0ccaa35d255fb090a269b1df35f0.zip
Merge pull request #13542 from robin850/issue-13530
Fix enum writers when using integers
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/enum.rb9
1 files changed, 7 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/enum.rb b/activerecord/lib/active_record/enum.rb
index 1d484f7c15..c042a2f232 100644
--- a/activerecord/lib/active_record/enum.rb
+++ b/activerecord/lib/active_record/enum.rb
@@ -1,5 +1,6 @@
module ActiveRecord
- # Declare an enum attribute where the values map to integers in the database, but can be queried by name. Example:
+ # 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 ]
@@ -23,6 +24,10 @@ module ActiveRecord
# conversation.status.nil? # => true
# conversation.status # => nil
#
+ # Scopes based on the allowed values of the enum field will be provided
+ # as well. With the above example, it will create an +active+ and +archived+
+ # scope.
+ #
# You can set the default value from the database declaration, like:
#
# create_table :conversations do |t|
@@ -67,7 +72,7 @@ module ActiveRecord
_enum_methods_module.module_eval do
# def status=(value) self[:status] = STATUS[value] end
define_method("#{name}=") { |value|
- unless enum_values.has_key?(value) || value.blank?
+ unless enum_values.has_key?(value) || enum_values.has_value?(value) || value.blank?
raise ArgumentError, "'#{value}' is not a valid #{name}"
end
self[name] = enum_values[value]