diff options
author | Robin Dupret <robin.dupret@gmail.com> | 2013-12-30 16:56:13 +0100 |
---|---|---|
committer | Robin Dupret <robin.dupret@gmail.com> | 2014-01-01 17:57:34 +0100 |
commit | 7aebcb67b040bca353cd2e97a468c8ffe4594665 (patch) | |
tree | 0f1a7aa25f08d91083686ada12d3771c0d7c8df2 /activerecord/lib | |
parent | 97ddfb48dbab8d9410e473f3f6e7e2d189b97b4f (diff) | |
download | rails-7aebcb67b040bca353cd2e97a468c8ffe4594665.tar.gz rails-7aebcb67b040bca353cd2e97a468c8ffe4594665.tar.bz2 rails-7aebcb67b040bca353cd2e97a468c8ffe4594665.zip |
Fix the enums writer methods
Previously, the writer methods would simply check whether the passed
argument was the symbol representing the integer value of an enum field.
Therefore, it was not possible to specify the numeric value itself but
the dynamically defined scopes generate where clauses relying on this
kind of values so a chained call to a method like `find_or_initialize_by`
would trigger an `ArgumentError`.
Reference #13530
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/enum.rb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/enum.rb b/activerecord/lib/active_record/enum.rb index 1d484f7c15..aebb061717 100644 --- a/activerecord/lib/active_record/enum.rb +++ b/activerecord/lib/active_record/enum.rb @@ -67,7 +67,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] |