Simple Behavior INSERT ON DUPLICATE KEY UPDATE or INSERT IGNORE
The preferred way to install this extension is through composer.
Either run
php composer.phar require kozhemin/yii2-insert-update-behavior:dev-master
or add
"kozhemin/yii2-insert-update-behavior": "dev-master"
to the require section of your composer.json
file.
This behavior allows you to create queries for INSERT ON DUPLICATE KEY UPDATE or INSERT IGNORE
For example:
Attach a new behavior to your model
public function behaviors()
{
return[
\kozhemin\dbHelper\InsertUpdate::className(),
];
}
usage
$dataInsert = [ ['title text', 'description'], ['title2 text', 'description2'], ['title3 text', 'descriptio3'] ];
//Optional column parameter
$column = ['title', 'description'];
//INSERT ON DUPLICATE KEY UPDATE
$model = new Post();
$model->InsertUpdate($dataInsert, $column)
or
//INSERT IGNORE
$model = new Post();
$model->insertIgnore($dataInsert, $column)