public function delete(array $options = []) {
        $options = $options + ['atomic' => true];
        $id = $this->get($this->primaryKey);

        if (!$id) {
            throw new MissingPrimaryKeyException(sprintf('Cannot delete %s record if no ID is present', get_class($this)));
        }

        $model = $this;
        $operation = function() use ($model, $id, $options) {
            if ($count = $model->getRepository()->delete($id, $options)) {
                $model->flush();

                return $count;
            }

            return 0;
        };

        // Wrap in a transaction if atomic
        if ($options['atomic']) {
            try {
                $count = $this->getRepository()->getDriver()->transaction($operation);
            } catch (Exception $e) {
                return 0;
            }
        } else {
            $count = call_user_func($operation);
        }

        return $count;
    }