Skip to content

Commit

Permalink
fixed null values in Json and Serializable fields
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Dec 12, 2019
1 parent 32cfc58 commit 0ad69cb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased
## [7.3.5] - 2019-12-12
### Added
- New function `getArray()` to SELECT queries, to return an array with data instead a `Row` or `RowCollection`.

### Fixed
- `NULL` values in `Json` and `Serializable` fields

## [7.3.4] - 2019-12-03
### Fixed
- Revert the bugfix added in v7.3.0 about not including `NULL` values on insert and fixed in a different way.
Expand Down Expand Up @@ -92,6 +95,7 @@ This library was rewritten and a lot of breaking changes were included.
- The pagination info is returned with `$selectQuery->getPageInfo()` function.
- Many other changes. See the docs.

[7.3.5]: https://github.com/oscarotero/simple-crud/compare/v7.3.4...v7.3.5
[7.3.4]: https://github.com/oscarotero/simple-crud/compare/v7.3.3...v7.3.4
[7.3.3]: https://github.com/oscarotero/simple-crud/compare/v7.3.2...v7.3.3
[7.3.2]: https://github.com/oscarotero/simple-crud/compare/v7.3.1...v7.3.2
Expand Down
4 changes: 4 additions & 0 deletions src/Fields/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public function format($value)

protected function formatToDatabase($value): ?string
{
if ($value === null) {
return $value;
}

if (!is_string($value)) {
return json_encode($value) ?: null;
}
Expand Down
4 changes: 4 additions & 0 deletions src/Fields/Serializable.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public function format($value)

protected function formatToDatabase($value): string
{
if ($value === null) {
return $value;
}

return serialize($value);
}
}
4 changes: 0 additions & 4 deletions tests/JsonFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,5 @@ public function testFields()
$post = $db->post[1];

$this->assertNull($post->info);

$array = $db->post->select()->one()->getArray();

print_r($array);
}
}

0 comments on commit 0ad69cb

Please sign in to comment.