Yii2: JsonExpression in Command::update() method

Created on 19 Feb 2018  Â·  5Comments  Â·  Source: yiisoft/yii2

What steps will reproduce the problem?

Update postgres table contains JSON(B) object using $connection->createCommand()->update () method

What is the expected result?

Updated record

What do you get instead?

Database Exception – yii\db\Exception
Object of class yii\db\JsonExpression could not be converted to string
Failed to prepare SQL: UPDATE "object_attributes" SET "attr_value"=:qp2 WHERE "UUID" = :uuid and "attr_name"=:attr_name
↵
Caused by: yii\base\ErrorException
Object of class yii\db\JsonExpression could not be converted to string
in /private/var/www/zzz/www/vendor/yiisoft/yii2/db/Command.php at line 315

  1. in /private/var/www/zzz/www/vendor/yiisoft/yii2/db/Command.php at line 263
bug

Most helpful comment

yii\db\ArrayExpression has the same error

All 5 comments

I faced the same thing after the update and it's really urgent for me, had to revert to 2.0.13.

yii\db\ArrayExpression has the same error

The fix will be included in patch-release

I've created a test to verify that SQL builds successfully. See 2eba4b54f

Could anyone post exact piece of code to reproduce the problem, please?

image

I tested here, and noticed that the problem occurs when you don't wrap the value in a JsonExpression.

Was this page helpful?
0 / 5 - 0 ratings