Skip to content

Commit 4ad04be

Browse files
committed
Fixed null saving for JSON and Array cols in AR
Fixes #15863
1 parent dd08c02 commit 4ad04be

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

framework/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Yii Framework 2 Change Log
1616
- Bug #15839: Fixed `yii\db\mysql\JsonExpressionBuilder` to cast JSON explicitly (silverfire)
1717
- Bug #15840: Fixed regression on load fixture data file (leandrogehlen)
1818
- Bug #15858: Fixed `Undefined offset` error calling `yii\helpers\Html::errorSummary()` with the same error messages for different model attributes (FabrizioCaldarelli, silverfire)
19+
- Bug #15863: Fixed saving of `null` attribute value for JSON and Array columns in MySQL and PostgreSQL (silverfire)
1920
- Bug: Fixed encoding of empty `yii\db\ArrayExpression` for PostgreSQL (silverfire)
2021
- Bug: Fixed table schema retrieving for PostgreSQL when the table name was wrapped in quotes (silverfire)
2122

framework/db/JsonExpression.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function getType()
8383
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
8484
* @return mixed data which can be serialized by <b>json_encode</b>,
8585
* which is a value of any type other than a resource.
86-
* @since 2.0.14.1
86+
* @since 2.0.14.2
8787
* @throws InvalidConfigException when JsonExpression contains QueryInterface object
8888
*/
8989
public function jsonSerialize()

framework/db/mysql/ColumnSchema.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ class ColumnSchema extends \yii\db\ColumnSchema
3434
*/
3535
public function dbTypecast($value)
3636
{
37+
if ($value === null) {
38+
return $value;
39+
}
40+
3741
if ($value instanceof ExpressionInterface) {
3842
return $value;
3943
}

framework/db/pgsql/ColumnSchema.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ class ColumnSchema extends \yii\db\ColumnSchema
5656
*/
5757
public function dbTypecast($value)
5858
{
59+
if ($value === null) {
60+
return $value;
61+
}
62+
5963
if ($value instanceof ExpressionInterface) {
6064
return $value;
6165
}

0 commit comments

Comments
 (0)