A
A
Alex Ershov2015-05-29 10:11:49
Yii
Alex Ershov, 2015-05-29 10:11:49

Yii2 How to do batchInsert with ON DUPLICATE KEY UPDATE?

yii\db\Command batchInsert( $table, $columns, $rows ) does not imply padding.
Tell me how to add to the request at the end
ON DUPLICATE KEY UPDATE
`price_current` = 7,
`price_old` = 2

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alex Ershov, 2015-05-29
@kilimandjaro

So far I see only one crutch option
Form an array for batchInsert -> copy it to a string using getRawSql -> add a condition to the string and execute the command through new sql

J
Jorik86, 2017-12-27
@Jorik86

specially made behavior for this https://github.com/kozhemin/yii2-insert-update-behavior

C
cr0de4, 2018-07-23
@cr0de4

Starting with Yii 2.0.14, you can use the upsert method of the QueryBuilder class

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question