Field can't update properties of casted value objects #4667
Replies: 1 comment
-
Is this of interest to others? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Context:
Grouping columns into a value object via $casts + a custom caster.
A field defined as
Text::make('Street', 'address.street')
can read its value from a casted object because resolving the value relies ondata_get()
which traverses objects if it can.Problem:
The same field can't be updated without workarounds because:
address_street
Field::fill
method relies on$model->{"address.street"}
which is implemented via magic method inHasAttribute::setAttribute
which doesn't rely on the reciprocaldata_set()
function.Question:
Does it make sense to try to ensure this kind of reciprocity?
data_get()
/data_set()
?Workaround1: I've defined
fillUsing()
callback to resolve this temporarily.Workaround2: you can override the magic
__get
method to usedata_set
-- this may have some unknown side effects if it circumvents other behaviors of attributes.Sidenote: Using
address->street
will work of you have a (json) column namedaddress
.Beta Was this translation helpful? Give feedback.
All reactions