Allow AR::Enum definitions with boolean values #38086
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
If
AR::Enum
is used for boolean field, it would be not expected behavior for us.fixes #38075
Problem
In case of using boolean for enum, we can set with string (hash key)
to instance, but we cannot set with actual value (hash value).
After looking into
AR::Enum::EnumType#cast
, I found thatblank?
method converts from false value to nil (it seems it may not intentional behavior).rails/activerecord/lib/active_record/enum.rb
Lines 125 to 135 in 1421ad5
In this patch, I improved that if it defines enum with boolean, it returns reasonable behavior.
Importance (Why it would be better to merge this patch)
post.status = 'disabled'
.post.disabled!
.^ This messages are translated by my co-worker @rastamhadi