Repository navigation
Allow default to be configured for serialization - #40545
Merged
Merged
Conversation
alpaca-tc
force-pushed
the
serialize_default
branch
from
November 5, 2020 05:31
dc8aa26 to
b1f41bd
Compare
kamipo
reviewed
Nov 5, 2020
Comment on lines
44
to
52
Member
There was a problem hiding this comment.
Can you also add a test for serialize on custom attribute with default?
def test_serialized_attribute_on_custom_attribute_with_default
klass = Class.new(ActiveRecord::Base) do
self.table_name = Topic.table_name
attribute :content, default: { key: "value" }
serialize :content, Hash
end
t = klass.new
assert_equal({ key: "value" }, t.content)
endWe've discussed about fixing the regression 8f2decd, and have agreed that allowing default to be configured with serialize is also useful, similar to #39820.
```ruby class Audit < ActiveRecord::Base serialize :content, JSON, default: [] end Audit.new.content #=> [] ```
alpaca-tc
force-pushed
the
serialize_default
branch
from
November 5, 2020 06:37
b1f41bd to
7d6cb95
Compare
kamipo
added a commit
that referenced
this pull request
Nov 5, 2020
Allow default to be configured for serialization
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Set the default value in the application layer for columns that can't have a default value, like MySQL's text columns.