D
D
Dilik Pulatov2017-04-27 20:01:20
MySQL
Dilik Pulatov, 2017-04-27 20:01:20

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

3 answer(s)
A
Anatoly Medvedev, 2017-04-27
@balamyt92

something like that.
DELETE FROM table WHERE id IN (1, 2, 3, 4, 5)

M
Maxim Timofeev, 2017-04-27
@webinar

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 question

Ask a Question

731 491 924 answers to any question