Relationmanager update rooted relations

Hello,

I'm trying to figure out how to save related attributes in a relation manager.

In first instance, I had to write a new table query, because the one given by Filament by default doesn't give me the correct items. The function looks like this;

protected function getTableQuery(): Builder
{
    return ActionsUsers::query()
        ->withoutGlobalScopes()
        ->leftJoin('actions', 'actions.id', '=', 'actions_users.action_id')
        ->where('actions.device_id', '=', $this->getOwnerRecord()->id)
        ->with([
            'action',
            'action.area',
            'action.property',
            'action.virtualDevice',
            'user',
            'action.device',
        ]);
}


Now, I get the correct data, but when I try to do things like this:

TextInput::make('action.virtualDevice.http_host')
    ->label('HTTP host')
    ->helperText('Do not end with a /')
    ->formatStateUsing(fn(ActionsUsers $record) => $record->action->virtualDevice?->endpoint)
    ->default(null),


I need to set the
formatStateUsing
, else it doesn't give any kind of values. When saving, I get nothing but exceptions when trying to save and the table it tries to save is also wrong. How can I resolve this issue?
Was this page helpful?