MAPG-131 adapt Modify to be able to handle external ID

This commit is contained in:
Bence Pőcze 2020-06-13 20:39:22 +02:00
parent 39e49724da
commit 6a191d5c28

View File

@ -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();
}