yii2 icon indicating copy to clipboard operation
yii2 copied to clipboard

DB batchInsert doesn't support JSON (array) fields

Open uaoleg opened this issue 1 month ago • 5 comments

PHP Warning ‘yii\base\ErrorException’ with message ‘Array to string conversion’
in vendor/yiisoft/yii2/db/QueryBuilder.php:485
Stack trace:
#0 vendor/yiisoft/yii2/db/QueryBuilder.php(485): yii\console\ErrorHandler->handleError(code: ‘...‘, message: ‘...‘, file: ‘...‘, line: ‘...‘)
#1 vendor/yiisoft/yii2/db/QueryBuilder.php(485): ::implode(separator: ‘...‘, array: ‘...‘)
#2 vendor/yiisoft/yii2/db/Command.php(525): yii\db\mysql\QueryBuilder->batchInsert(table: ‘...‘, columns: ‘...‘, rows: ‘...‘, params: ‘...‘)

uaoleg avatar Nov 19 '25 16:11 uaoleg

Fixed: https://github.com/yiisoft/yii2/pull/20684/files

uaoleg avatar Nov 19 '25 16:11 uaoleg

Are you sure it's JSON strings in all possible cases?

samdark avatar Nov 20 '25 17:11 samdark

@samdark sorry didn't get your question

uaoleg avatar Nov 20 '25 17:11 uaoleg

I was trying to save a record that had a field with array value

uaoleg avatar Nov 20 '25 17:11 uaoleg

Yes. I've got the idea. Was just too much into Yii3 which supports more than a single way to store arrays.

samdark avatar Nov 20 '25 18:11 samdark