Skip to content

Commit 7ddddbc

Browse files
authored
Merge pull request #23 from flavioheleno/master
Avoid calling lastInsertId on entity updates
2 parents 9390332 + 78a15a7 commit 7ddddbc

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/Infrastructure/Model/Repository/Sql/SqlWriteRepository.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ public function add(Identity $value)
4343
{
4444
try {
4545
$this->updateQuery($value);
46+
$insert = false;
4647
} catch (PDOException $e) {
4748
$this->insertQuery($value);
49+
$insert = true;
4850
}
4951

5052
$id = $value->id();
51-
if ($this->mapping->autoGenerateId()) {
53+
if (($insert) && ($this->mapping->autoGenerateId())) {
5254
$id = $this->queryBuilder()->getConnection()->lastInsertId();
5355
}
5456

0 commit comments

Comments
 (0)