From 4a3544582c570d43f7d274ddbae7ea835176cbd9 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Tue, 28 Jan 2020 01:33:29 +0100 Subject: [PATCH] Add parameter for "toArray()" method --- src/BaseModel.php | 11 +++++++++-- src/BaseRepository.php | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/BaseModel.php b/src/BaseModel.php index 791d6887c..decc62752 100644 --- a/src/BaseModel.php +++ b/src/BaseModel.php @@ -129,9 +129,16 @@ abstract class BaseModel $this->data[$name] = $value; } - public function toArray() + /** + * Returns the values of the current model as an array + * + * @param bool $dbOnly True, if just the db-relevant fields should be returned + * + * @return array The values of the current model + */ + public function toArray(bool $dbOnly = false) { - return $this->mapFields($this->data); + return $dbOnly ? $this->mapFields($this->data) : $this->data; } protected function checkValid() diff --git a/src/BaseRepository.php b/src/BaseRepository.php index cce1c50c1..c14d6f7bc 100644 --- a/src/BaseRepository.php +++ b/src/BaseRepository.php @@ -122,7 +122,7 @@ abstract class BaseRepository extends BaseFactory */ public function update(BaseModel $model) { - if ($this->dba->update(static::$table_name, $model->toArray(), ['id' => $model->id], $model->getOriginalData())) { + if ($this->dba->update(static::$table_name, $model->toArray(true), ['id' => $model->id], $model->getOriginalData())) { $model->resetOriginalData(); return true; }