public function commit(Model $model)
    {
        $this->dispatchLifecycleEvent(Events::preCommit, $model);

        if (false === $this->shouldCommit($model)) {
            return $model;
        }

        if (true === $model->getState()->is('new')) {
            $this->doCommitCreate($model);

        } elseif (true === $model->getState()->is('deleting')) {
            // Deletes must execute before updates to prevent an update then a delete.
            $this->doCommitDelete($model);

        } elseif (true === $model->isDirty()) {
            $this->doCommitUpdate($model);

        } else {
            throw new \RuntimeException('Unable to commit model.');
        }

        $this->dispatchLifecycleEvent(Events::postCommit, $model);

        return $model;
    }