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:
Repeater::make('activities')
->schema([
TextInput::make('day')->numeric()->required()->unique()->dehydrated(false),
TagsInput::make('activity')->required()->hint('press enter to add new')->dehydrated(false),
])
->label('Daily activities')
->dehydrated(false),
Repeater::make('activities')
->schema([
TextInput::make('day')->numeric()->required()->unique()->dehydrated(false),
TagsInput::make('activity')->required()->hint('press enter to add new')->dehydrated(false),
])
->label('Daily activities')
->dehydrated(false),
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
Patrick Boivin
Patrick Boivin17mo ago
What's the error about the dehydrated fields?
petersowah
petersowahOP16mo ago
The fields are day and activity @pboivin
Patrick Boivin
Patrick Boivin16mo ago
Sure, what is the error message saying?
petersowah
petersowahOP16mo ago
Column not found: 1054 Unknown column 'day' in 'where clause'
Column not found: 1054 Unknown column 'day' in 'where clause'
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
Patrick Boivin
Patrick Boivin16mo ago
So the entire activities repeater should not be dehydrated?
petersowah
petersowahOP16mo ago
Yes
awcodes
awcodes16mo ago
If you don’t dehydrate it then it won’t be available in the form data when you try to manipulate it.
petersowah
petersowahOP16mo ago
I don' t want the data to be persisted to the database but someway somehow, I get a database exception about the dehydrated field.
awcodes
awcodes16mo ago
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.
petersowah
petersowahOP16mo ago
OK. Any idea at which point this query gets executed?
select count(*) as aggregate from `tours` where `day` = 1
select count(*) as aggregate from `tours` where `day` = 1
This is before the data gets saved to the database. There's no column day, hence why the error was thrown This
$data = $this->form->getState();
$data = $this->form->getState();
throws an exception when it's called. I think it executes the query at some point. It's in the CreateRecord class
wyChoong
wyChoong16mo ago
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(*) query
petersowah
petersowahOP16mo ago
Thanks. I'll check it out. 🙏
wyChoong
wyChoong16mo ago
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
petersowah
petersowahOP16mo ago
Thanks @wychoong that helped a lot. I'm unblocked now. Thanks to @awcodes @pboivin too! I appreciate all the help on this one.
Want results from more Discord servers?
Add your server