Answer the question
In order to leave comments, you need to log in
How to delete multiple records in one query (in Yii2)?
Hello!
could you tell me how can i delete more than one record in one query?
for example, in my array there are several category IDs .... I need to delete all entries that have one of these category IDs. sometimes there will be a lot of IDs... so inside the cycle I don't want to make a request to delete a post... (many people know this is a stupid thing)
if it's difficult in Yii2 then can you write a SQL query? and is it possible?
Answer the question
In order to leave comments, you need to log in
something like that.DELETE FROM table WHERE id IN (1, 2, 3, 4, 5)
Category::deleteAll(['category_id'=>$id]);
But keep in mind that events will not fire in this case (beforeDelete and afterDelete)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question