Delete multiple rows in YII2

You can painlessly remove ->select('master_list_contacts.*').

->innerJoin('master_contacts', '`master_contacts`.`id` = `master_list_contacts`.`master_contact_id`')

performs the same work that ->joinWith('masterContact').

For delete entites try use this code:

MasterListContacts::deleteAll(['user_id' => \Yii::$app->user->identity->id, 'slug' => $slug]);

Found better solution:

\Yii::$app
    ->db
    ->createCommand()
    ->delete('master_contacts', ['id' => $deletableMasterContacts])
    ->execute();

Where $deletableMasterContacts is array of master_contacts ids, which should be deleted

Tags:

Yii2