Dehydrating fields not working.
I have a repeater with fields inside. The data in the repeater field will be mutated before saving to the database. However, when I try saving the form, I get an error about the dehydrated fields which are only presentational. Please see snippet below:
I only need the data in here so I can mutate the data object before saving to the database. Thank you very much!
15 Replies
What's the error about the dehydrated fields?
The fields are
day
and activity
@pboivinSure, what is the error message saying?
The column day does not exist in the tours table. I use the data to construct a json object which is stored in a json column on tours. @pboivin
So the entire
activities
repeater should not be dehydrated?Yes
If you don’t dehydrate it then it won’t be available in the form data when you try to manipulate it.
I don' t want the data to be persisted to the database but someway somehow, I get a database exception about the dehydrated field.
So, you need to override the save / create methods to remove those from the data after you’ve mutated it then manually save / create the record.
OK. Any idea at which point this query gets executed?
This is before the data gets saved to the database. There's no column day, hence why the error was thrown
This throws an exception when it's called. I think it executes the query at some point. It's in the CreateRecord class
so, in filament when you do
$this->form->getState()
, it will handles the relationship then the record
so in your case the repeater is being processed, and you have the unique()
validation which causes the count(*) querycustomize the rule here https://filamentphp.com/docs/3.x/forms/validation#unique
Thanks. I'll check it out. 🙏
then for mutating your repeater fields, check this doc if you haven't
https://filamentphp.com/docs/3.x/forms/fields/repeater#mutating-related-item-data-before-creating mutateRelationshipDataBeforeCreateUsing / mutateRelationshipDataBeforeSaveUsing
Thanks @wychoong that helped a lot. I'm unblocked now. Thanks to @awcodes @pboivin too! I appreciate all the help on this one.