Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the database type to deserialize enum
This fixes incorrect assumptions made by e991c7b that we can assume the DB is already casting the value for us. The enum type needs additional information to perform casting, and needs a subtype. I've opted not to call `super` in `cast`, as we have a known set of types which we accept there, and the subtype likely doesn't accept them (symbol -> integer doesn't make sense) Close #23190
- Loading branch information
Showing
4 changed files
with
19 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ class Book < ActiveRecord::Base | |
enum author_visibility: [:visible, :invisible], _prefix: true | ||
enum illustrator_visibility: [:visible, :invisible], _prefix: true | ||
enum font_size: [:small, :medium, :large], _prefix: :with, _suffix: true | ||
enum cover: { hard: 'hard', soft: 'soft' } | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
sgrif
via email
Author
Contributor
|
||
|
||
def published! | ||
super | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@sgrif This seems to be the first time there was a test case around Enum with db values that were Strings rather than integers.
But it's associated with a few PR's and Issues that are about default values in Enums, and don't seem to mention db types or if/when/that db strings are supported as well as Integers.
Something that's still not documented anywhere, such as the Enum class header inline docs!
Curious if you know anything about the origin/history of Enum supporting String db values? I was wishing it did, and went to look at the source -- to find that it already did. At least in Rails5. Now I'm very curious.