From 33c90f06dd57a700034f108064328b34143cd8d6 Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Tue, 7 Jan 2025 21:42:40 -0300 Subject: [PATCH] FIX: Index Respository --- app/common/Ideal/Repository.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/app/common/Ideal/Repository.php b/app/common/Ideal/Repository.php index 4858ee9..7512040 100644 --- a/app/common/Ideal/Repository.php +++ b/app/common/Ideal/Repository.php @@ -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 {