MAPG-131 adapt Modify to be able to handle external ID
This commit is contained in:
parent
39e49724da
commit
6a191d5c28
@ -16,6 +16,8 @@ class Modify
|
|||||||
|
|
||||||
private array $original = [];
|
private array $original = [];
|
||||||
|
|
||||||
|
private ?string $externalId = null;
|
||||||
|
|
||||||
private bool $autoIncrement = true;
|
private bool $autoIncrement = true;
|
||||||
|
|
||||||
public function __construct(IConnection $connection, string $table)
|
public function __construct(IConnection $connection, string $table)
|
||||||
@ -31,6 +33,13 @@ class Modify
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setExternalId($id): Modify
|
||||||
|
{
|
||||||
|
$this->externalId = $id;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function setAutoIncrement(bool $autoIncrement = true): Modify
|
public function setAutoIncrement(bool $autoIncrement = true): Modify
|
||||||
{
|
{
|
||||||
$this->autoIncrement = $autoIncrement;
|
$this->autoIncrement = $autoIncrement;
|
||||||
@ -87,7 +96,9 @@ class Modify
|
|||||||
|
|
||||||
private function insert(): void
|
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();
|
$this->attributes[$this->idName] = $this->generateKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user