Update only one field in a custom action?

Hi guys,

I would like to implement this:
  • if the user clicked the edit button, the edit form open
  • the form has multiple form components and a key-value component (this value stored in another table with HasOne relation)
  • the user made some changes then submit the edit form
  • after submit only one field (is_active) has been updated in the edited record, then a new record created with the posted data
I try this:
protected function handleRecordUpdate(Model $record, array $data): Model
{
$record->update(['is_active' => 0]);
return static::getModel()::create($data);
}

Problem:
All fields of original record has been updated (the related record has been updated too).

How can i solve this? Thanks a lot!
Was this page helpful?