[Importer] Only update values that are empty/null

So I am writing a lot of importers and exporters, love the proces. Now i have a bit of a weird problem, I have a table "suppliers" and there I want the following behaviour:
1) Supplier doesnt exist, create new one
2) Supplier does exist: only update values that are missing.

One is easy, but how can I do two? What is the most efficient way to do this? Maybe sth like:

    protected function beforeUpdate(): void
    {
        // check here all fields if they are changed and if so reset? (ugly solution!)
    }


Should be some easier way right?
Solution
Now did it like this, seems to be working:
    protected function beforeFill(): void
    {
        if(isset($this->record) && $this->record->exists) {
            // Cycle through the columns and only leave the ones that are not empty
            foreach ($this->record->getAttributes() as $key => $value) {
                if (!empty($value)) {
                    unset($this->data[$key]);
                }
            }
        }

    }
Was this page helpful?