MorphOne mutateRelationshipDataBeforeCreateUsing does not work properly

For some reason, if I use mutateRelationshipDataBeforeCreateUsing() the related model gets created with the correct values used in the closure, but Filament runs an update query right after the creation, with the original data inputted. I can also confirm this by using mutateRelationshipDataBeforeSaveUsing(), because this runs as well and does not have the mutated data from mutateRelationshipDataBeforeCreateUsing().

I'm confused, why Filament does behave like this.

It's a problem, because I cannot set my token without getting SQL exceptions, when Filament tries to update it immediately after creation with the wrong value.

Code:
                Forms\Components\Section::make()
                    ->relationship('qrToken')
                    ->schema([
                        Forms\Components\TextInput::make('token'),
                    ])
                    ->mutateRelationshipDataBeforeCreateUsing(function (array $data) {
                        $data['token'] = QRCodeService::generateQRCodeToken();

                        return $data;
                    })
                    ->mutateRelationshipDataBeforeSaveUsing(function (array $data) {
                        dd($data); // --> Outputs the value inputted by the user NOT the mutated one.
                    return $data;
                }),
Was this page helpful?