public function getDbValue()
    {
        $value = $this->getValue();
        if (is_null($value)) {
            // Process default value
            $value = $this->getDefaultValue();
            if ($this->isInstanceOf($value, AbstractEntity::class)) {
                if (!$value->exists()) {
                    $value->save();
                }

                $value = $value->id;
            }

            return $this->processToDbValue($value);
        }

        // Save if new or if updating is allowed
        if (!$value->exists() || $this->getUpdateExisting()) {
            $value->save();
        }

        return $this->processToDbValue($value->id);
    }