From f01f7a5ddb737b197f6de052defecd4664796850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aryel=20Mota=20G=C3=B3is?= Date: Fri, 6 Jul 2018 23:36:19 -0300 Subject: [PATCH 1/3] Fix Model::addColumnTypeKeys() --- CHANGELOG.md | 7 +++++++ src/Model.php | 14 ++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 263f246..88a26b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Changed +- `getTypedColumns()` returns an associative array + +### Fixed +- When adding changes in a different order from `COLUMNS`, data was being saved + in wrong columns in the database + ## [5.1.0] - 2018-05-28 diff --git a/src/Model.php b/src/Model.php index 277190d..b0d5fc0 100644 --- a/src/Model.php +++ b/src/Model.php @@ -520,7 +520,7 @@ public static function dump($where = [], $columns = []) { $columns = (empty($columns)) ? static::COLUMNS - : self::getTypedColumns($columns); + : array_values(self::getTypedColumns($columns)); $database = self::getDatabase(); return $database->select(static::TABLE, $columns, $where); @@ -667,13 +667,13 @@ final public static function getTypedColumns($columns) { static::checkUnknownColumn($columns); - $result = array_values(Utils::arrayWhitelist( + $result = Utils::arrayWhitelist( array_combine(self::getColumns(), static::COLUMNS), (array) $columns - )); + ); return (is_string($columns)) - ? $result[0] + ? array_values($result)[0] : $result; } @@ -831,10 +831,8 @@ public function undo(string $column = null) */ final public static function addColumnTypeKeys(array $data) { - return array_combine( - self::getTypedColumns(array_keys($data)), - $data - ); + $columns = self::getTypedColumns(array_keys($data)); + return array_combine($columns, array_merge($columns, $data)); } /** From 4704cd6e69caf553caaf9ea6a341253b21084c74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aryel=20Mota=20G=C3=B3is?= Date: Sat, 7 Jul 2018 00:05:12 -0300 Subject: [PATCH 2/3] Partially revert "Let COLUMNS define prefered data type" Commit: e67b0a35d43ed684cd3e84be75598cdb1fb7514c --- CHANGELOG.md | 2 ++ src/Model.php | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88a26b9..447388e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed - When adding changes in a different order from `COLUMNS`, data was being saved in wrong columns in the database +- Column types are only used when fetching data, and must be avoided when + sending data to the database ## [5.1.0] - 2018-05-28 diff --git a/src/Model.php b/src/Model.php index b0d5fc0..df7990f 100644 --- a/src/Model.php +++ b/src/Model.php @@ -1118,8 +1118,7 @@ public function updateStampColumns($subset = null) /** * Tells if the model has valid data * - * It may change the data to remove unwanted content, and adds the column - * data types + * It may change the data to remove unwanted content * * @param mixed[] $data Data to be validated * @param boolean $full If $data is supposed to contain all columns @@ -1160,7 +1159,7 @@ protected static function validate($data, $full) : array_replace($data, $result); } - return static::addColumnTypeKeys($data); + return $data; } /* From 35ed8a3216b7694c6c25cb96dd1b25f4db16186f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aryel=20Mota=20G=C3=B3is?= Date: Sat, 7 Jul 2018 00:08:21 -0300 Subject: [PATCH 3/3] Prepare 5.1.1 --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 447388e..ca5b7f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] + +## [5.1.1] - 2018-07-07 + ### Changed - `getTypedColumns()` returns an associative array @@ -264,7 +267,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - DatabaseObject.php -[Unreleased]: https://github.com/aryelgois/Medools/compare/v5.1.0...develop +[Unreleased]: https://github.com/aryelgois/Medools/compare/v5.1.1...develop +[5.1.1]: https://github.com/aryelgois/Medools/compare/v5.1.0...v5.1.1 [5.1.0]: https://github.com/aryelgois/Medools/compare/v5.0.0...v5.1.0 [5.0.0]: https://github.com/aryelgois/Medools/compare/v4.3.0...v5.0.0 [4.3.0]: https://github.com/aryelgois/Medools/compare/v4.2.0...v4.3.0