FIX: Index Respository
This commit is contained in:
@ -25,7 +25,7 @@ abstract class Repository implements Define\Repository
|
||||
public function load(array $data_row): Define\Model
|
||||
{
|
||||
$model = $this->create($data_row);
|
||||
$model->{$this->getKey()} = $data_row[$this->getKey()];
|
||||
$model->{$this->getIndex()} = $data_row[$this->getKey()];
|
||||
return $model;
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ abstract class Repository implements Define\Repository
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->delete()->from($this->getTable())
|
||||
->where("{$this->getKey()} = ?");
|
||||
$this->connection->execute($query, [$model->{$this->getKey()}]);
|
||||
$this->connection->execute($query, [$model->{$this->getIndex()}]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,6 +73,18 @@ abstract class Repository implements Define\Repository
|
||||
{
|
||||
return $this->key;
|
||||
}
|
||||
|
||||
protected string $index = 'id';
|
||||
public function setIndex(string $index): Repository
|
||||
{
|
||||
$this->index = $index;
|
||||
return $this;
|
||||
}
|
||||
protected function getIndex(): string
|
||||
{
|
||||
return $this->index;
|
||||
}
|
||||
|
||||
protected function parseData(Define\Model $model, ?array $data, Implement\Repository\MapperParser $data_map): Define\Model
|
||||
{
|
||||
if ($data === null) {
|
||||
@ -146,9 +158,9 @@ abstract class Repository implements Define\Repository
|
||||
->update($this->getTable())
|
||||
->set($columns_string)
|
||||
->where("{$this->getKey()} = ?");
|
||||
$values []= $model->{$this->getKey()};
|
||||
$values []= $model->{$this->getIndex()};
|
||||
$this->connection->execute($query, $values);
|
||||
return $this->fetchById($model->{$this->getKey()});
|
||||
return $this->fetchById($model->{$this->getIndex()});
|
||||
}
|
||||
protected function fetchOne(string $query, ?array $data = null): Define\Model
|
||||
{
|
||||
|
Reference in New Issue
Block a user