[12.x] clarify how to "set" value objects with custom casts #10342
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.
the current wording only accounts for 1 of the 2 scenarios that can occur when using a custom cast with a value object. that Value Object can encompasses either 1 or many values on the model.
the current documentation addresses the example of an
Address
, which would have multiple fields like "line1", "line2", "city", etc. thisset
method should return the array as currently documented.an example of a single value Value Object would be a phone number. a user might want it as an value object rather than a raw number to encapsulate behavior. this
set
method should return a string.there is one distinct advantage to returning a string vs an array. it prevents the cast from being tied to explicit model field names. this allows a field of any name to use the cast:
if a user returns an array from this simple 1 value cast, the cast loses its flexibility and the above example does not work.