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
|
public function load(array $data_row): Define\Model
|
||||||
{
|
{
|
||||||
$model = $this->create($data_row);
|
$model = $this->create($data_row);
|
||||||
$model->{$this->getIndex()} = $data_row[$this->getKey()];
|
$this->setIndex($model, $data_row[$this->getKey()]);
|
||||||
return $model;
|
return $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ abstract class Repository implements Define\Repository
|
|||||||
$query = $this->connection->getQueryBuilder()
|
$query = $this->connection->getQueryBuilder()
|
||||||
->delete()->from($this->getTable())
|
->delete()->from($this->getTable())
|
||||||
->where("{$this->getKey()} = ?");
|
->where("{$this->getKey()} = ?");
|
||||||
$this->connection->execute($query, [$model->{$this->getIndex()}]);
|
$this->connection->execute($query, [$this->getIndex($model)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -74,15 +74,14 @@ abstract class Repository implements Define\Repository
|
|||||||
return $this->key;
|
return $this->key;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected string $index = 'id';
|
protected function setIndex(Define\Model &$model, mixed $value): Repository
|
||||||
public function setIndex(string $index): Repository
|
|
||||||
{
|
{
|
||||||
$this->index = $index;
|
$model->id = $value;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
protected function getIndex(): string
|
protected function getIndex(Define\Model $model): mixed
|
||||||
{
|
{
|
||||||
return $this->index;
|
return $model->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function parseData(Define\Model $model, ?array $data, Implement\Repository\MapperParser $data_map): Define\Model
|
protected function parseData(Define\Model $model, ?array $data, Implement\Repository\MapperParser $data_map): Define\Model
|
||||||
@ -158,9 +157,9 @@ abstract class Repository implements Define\Repository
|
|||||||
->update($this->getTable())
|
->update($this->getTable())
|
||||||
->set($columns_string)
|
->set($columns_string)
|
||||||
->where("{$this->getKey()} = ?");
|
->where("{$this->getKey()} = ?");
|
||||||
$values []= $model->{$this->getIndex()};
|
$values []= $this->getIndex($model);
|
||||||
$this->connection->execute($query, $values);
|
$this->connection->execute($query, $values);
|
||||||
return $this->fetchById($model->{$this->getIndex()});
|
return $this->fetchById($this->getIndex($model));
|
||||||
}
|
}
|
||||||
protected function fetchOne(string $query, ?array $data = null): Define\Model
|
protected function fetchOne(string $query, ?array $data = null): Define\Model
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user