I have an array of objects fetched from database:
$masterListContacts = MasterListContacts::find()
->select('master_list_contacts.*')
->innerJoin('master_contacts', '`master_contacts`.`id` = `master_list_contacts`.`master_contact_id`')
->with('masterContact')
->where(['user_id' => \Yii::$app->user->identity->id, 'slug' => $slug])
->all();
Under certain circumstances, I need to delete all rows from the database represented in this array. But with both delete() and deleteAll() methods I got an error Call to a member function ... on array
. Could someone tell me please which one the best way to accomplish this?
UPDATE: Here is my database structure.
You can painlessly remove
->select('master_list_contacts.*')
.performs the same work that
->joinWith('masterContact')
.For delete entites try use this code:
Found better solution:
Where
$deletableMasterContacts
is array of master_contacts ids, which should be deleted