Skip to content

Commit

Permalink
Merge branch 'hotfix'
Browse files Browse the repository at this point in the history
  • Loading branch information
aryelgois committed Jul 7, 2018
2 parents cdae1cc + 35ed8a3 commit 0dc32ae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ 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

### 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

### Added
Expand Down Expand Up @@ -255,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
Expand Down
19 changes: 8 additions & 11 deletions src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -1120,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
Expand Down Expand Up @@ -1162,7 +1159,7 @@ protected static function validate($data, $full)
: array_replace($data, $result);
}

return static::addColumnTypeKeys($data);
return $data;
}

/*
Expand Down

0 comments on commit 0dc32ae

Please sign in to comment.