diff --git a/application/Espo/Core/Repositories/Database.php b/application/Espo/Core/Repositories/Database.php index d13ea2c1e2..b7d3d3a4fb 100644 --- a/application/Espo/Core/Repositories/Database.php +++ b/application/Espo/Core/Repositories/Database.php @@ -33,6 +33,7 @@ use Espo\Core\Name\Field; use Espo\Core\ORM\Repository\Option\SaveOption; use Espo\Core\Utils\SystemUser; use Espo\ORM\BaseEntity; +use Espo\ORM\Defs\Params\AttributeParam; use Espo\ORM\Defs\Params\RelationParam; use Espo\ORM\Entity; use Espo\ORM\Relation\RelationsMap; @@ -129,7 +130,7 @@ class Database extends RDBRepository if ( $entity->isNew() && !$entity->has(self::ATTR_ID) && - !$this->getAttributeParam($entity, self::ATTR_ID, 'autoincrement') + !$this->getAttributeParam($entity, self::ATTR_ID, AttributeParam::AUTOINCREMENT) ) { $entity->set(self::ATTR_ID, $this->recordIdGenerator->generate()); } diff --git a/application/Espo/Core/Utils/Database/Orm/Converter.php b/application/Espo/Core/Utils/Database/Orm/Converter.php index 3f60a380d7..8f571ff8b7 100644 --- a/application/Espo/Core/Utils/Database/Orm/Converter.php +++ b/application/Espo/Core/Utils/Database/Orm/Converter.php @@ -82,7 +82,7 @@ class Converter 'len' => AttributeParam::LEN, // @todo Revise. FieldParam::NOT_NULL => AttributeParam::NOT_NULL, 'exportDisabled' => CoreAttributeParam::NOT_EXPORTABLE, - 'autoincrement' => 'autoincrement', + FieldParam::AUTOINCREMENT => AttributeParam::AUTOINCREMENT, 'entity' => 'entity', FieldParam::NOT_STORABLE => AttributeParam::NOT_STORABLE, 'link' => AttributeParam::RELATION, diff --git a/application/Espo/ORM/Defs/AttributeDefs.php b/application/Espo/ORM/Defs/AttributeDefs.php index bde07bde65..b4e5bc8f79 100644 --- a/application/Espo/ORM/Defs/AttributeDefs.php +++ b/application/Espo/ORM/Defs/AttributeDefs.php @@ -92,7 +92,7 @@ class AttributeDefs */ public function isAutoincrement(): bool { - return $this->data['autoincrement'] ?? false; + return $this->data[AttributeParam::AUTOINCREMENT] ?? false; } /** diff --git a/application/Espo/ORM/Defs/Params/AttributeParam.php b/application/Espo/ORM/Defs/Params/AttributeParam.php index 6652ac1870..15de1685dc 100644 --- a/application/Espo/ORM/Defs/Params/AttributeParam.php +++ b/application/Espo/ORM/Defs/Params/AttributeParam.php @@ -59,6 +59,11 @@ class AttributeParam */ public const NOT_NULL = 'notNull'; + /** + * Autoincrement. + */ + public const AUTOINCREMENT = 'autoincrement'; + /** * A default value. */ diff --git a/application/Espo/ORM/Defs/Params/FieldParam.php b/application/Espo/ORM/Defs/Params/FieldParam.php index 7fc7cb0caa..aba63a07b0 100644 --- a/application/Espo/ORM/Defs/Params/FieldParam.php +++ b/application/Espo/ORM/Defs/Params/FieldParam.php @@ -49,6 +49,11 @@ class FieldParam */ public const DB_TYPE = 'dbType'; + /** + * Autoincrement. + */ + public const AUTOINCREMENT = 'autoincrement'; + /** * A max length. */ diff --git a/application/Espo/ORM/Mapper/BaseMapper.php b/application/Espo/ORM/Mapper/BaseMapper.php index 59a2499dd0..b86a5e684b 100644 --- a/application/Espo/ORM/Mapper/BaseMapper.php +++ b/application/Espo/ORM/Mapper/BaseMapper.php @@ -1308,7 +1308,7 @@ class BaseMapper implements RDBMapper $this->queryExecutor->execute($query); - if ($this->getAttributeParam($entity, Attribute::ID, 'autoincrement')) { + if ($this->getAttributeParam($entity, Attribute::ID, AttributeParam::AUTOINCREMENT)) { $this->setLastInsertIdWithinConnection($entity); } } @@ -1564,7 +1564,7 @@ class BaseMapper implements RDBMapper $onlyStorable && ( $this->getAttributeParam($entity, $attribute, AttributeParam::NOT_STORABLE) || - $this->getAttributeParam($entity, $attribute, 'autoincrement') || + $this->getAttributeParam($entity, $attribute, AttributeParam::AUTOINCREMENT) || ( $this->getAttributeParam($entity, $attribute, 'source') && $this->getAttributeParam($entity, $attribute, 'source') !== 'db'