简体   繁体   中英

How to delete an ActiveRecord in Yii2

I have a quick question. I have a model that I gotta get rid off. I have tried something like the following, but I get an error called Call to a member function delete() on array :

This is what I have tried so far.

$foundTeams = UserHasTeam::find()->where(['user_has_team.user_iduser' => $model->id])->all();
$foundTeams->delete();

There is static method deleteAll() for this in ActiveRecord .

UserHasTeam::deleteAll(['user_iduser' => $model->id]);

This will delete all rows from UserHasTeam::tableName() where user_iduser is $model->id .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM