public function save(Record $model)
    {
        $pk = $this->getPrimaryKey();

        if (isset($model->{$pk})) {
            $model->update();

            return $model->{$pk};
        } else {
            /** @var Record $previous */
            $previous = $model->exists();

            if ($previous) {
                $data = $model->toArray();

                if ($data) {
                    $previous->writeData($model->toArray());
                }
                $previous->update();

                $model->writeData($previous->toArray());

                return $model->getPrimaryKey();
            }
        }

        $model->insert();

        return $model->getPrimaryKey();
    }