src/Row.php
public function save(): self
    {
        if (!empty($this->changes)) {
            $eventDispatcher = $this->table->getEventDispatcher();

            if ($eventDispatcher) {
                $eventDispatcher->dispatch(new BeforeSaveRow($this));
            }

            if (empty($this->id)) {
                $this->id = $this->table->insert($this->changes)->run();
            } else {
                $this->table->update($this->changes)
                    ->where('id = ', $this->id)
                    ->run();
            }

            $this->values = $this->toArray();
            $this->changes = [];
            $this->table->cache($this);
        }

        return $this;
    }
public function save(): self
    {
        if (!empty($this->changes)) {
            $eventDispatcher = $this->table->getEventDispatcher();

            if ($eventDispatcher) {
                $eventDispatcher->dispatch(new BeforeSaveRow($this));
            }

            if (empty($this->id)) {
                $this->id = $this->table->insert($this->changes)->run();
            } else {
                $this->table->update($this->changes)
                    ->where('id = ', $this->id)
                    ->run();
            }

            $this->values = $this->toArray();
            $this->changes = [];
            $this->table->cache($this);
        }

        return $this;
    }
Insert/update the row in the database