FIX: Index Respository

This commit is contained in:
Juan Pablo Vial
2025-01-07 21:42:40 -03:00
parent 3771af0282
commit 33c90f06dd

View File

@ -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->getIndex()} = $data_row[$this->getKey()];
$this->setIndex($model, $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->getIndex()}]);
$this->connection->execute($query, [$this->getIndex($model)]);
}
/**
@ -74,15 +74,14 @@ abstract class Repository implements Define\Repository
return $this->key;
}
protected string $index = 'id';
public function setIndex(string $index): Repository
protected function setIndex(Define\Model &$model, mixed $value): Repository
{
$this->index = $index;
$model->id = $value;
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
@ -158,9 +157,9 @@ abstract class Repository implements Define\Repository
->update($this->getTable())
->set($columns_string)
->where("{$this->getKey()} = ?");
$values []= $model->{$this->getIndex()};
$values []= $this->getIndex($model);
$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
{