set id for autoincrement after insert

This commit is contained in:
Yuri Kuznetsov
2020-08-19 11:36:49 +03:00
parent 65929eec4b
commit 05409dacde
+23 -1
View File
@@ -45,6 +45,8 @@ use Espo\ORM\{
};
use PDO;
use PDOStatement;
use Exception;
use LogicException;
use RuntimeException;
@@ -1231,7 +1233,27 @@ abstract class BaseMapper implements Mapper
])
);
$this->executeSql($sql, true);
$sth = $this->executeSql($sql, true);
if ($entity->getAttributeParam('id', 'autoincrement')) {
$this->setLastInsertIdWithinConnection($entity);
}
}
protected function setLastInsertIdWithinConnection(Entity $entity)
{
$id = $this->pdo->lastInsertId();
if ($id === '' || $id === null) {
return;
}
if ($entity->getAttributeType('id') === Entity::INT) {
$id = (int) $id;
}
$entity->set('id', $id);
$entity->setFetched('id', $id);
}
/**