From 6a191d5c280e8a725348613243ba068a83d36a65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sat, 13 Jun 2020 20:39:22 +0200 Subject: [PATCH] MAPG-131 adapt Modify to be able to handle external ID --- src/Database/Query/Modify.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Database/Query/Modify.php b/src/Database/Query/Modify.php index 6c84496..f731461 100755 --- a/src/Database/Query/Modify.php +++ b/src/Database/Query/Modify.php @@ -16,6 +16,8 @@ class Modify private array $original = []; + private ?string $externalId = null; + private bool $autoIncrement = true; public function __construct(IConnection $connection, string $table) @@ -31,6 +33,13 @@ class Modify return $this; } + public function setExternalId($id): Modify + { + $this->externalId = $id; + + return $this; + } + public function setAutoIncrement(bool $autoIncrement = true): Modify { $this->autoIncrement = $autoIncrement; @@ -87,7 +96,9 @@ class Modify private function insert(): void { - if (!$this->autoIncrement) { + if ($this->externalId !== null) { + $this->attributes[$this->idName] = $this->externalId; + } elseif (!$this->autoIncrement) { $this->attributes[$this->idName] = $this->generateKey(); }