5

我正在尝试从这样的RestoFoods模型中删除数据:

RestoFoods::deleteAll(["restaurant_id"=>$postData['resto_id'], 'food_id NOT IN'=> [1,2] ]);

我想要这个sql:

DELETE FROM `resto_foods` WHERE `restaurant_id`=1 AND (`food_id` NOT IN (1, 2));
4

1 回答 1

8

你可以试试这个方法

RestoFoods::deleteAll(['AND', 'restaurant_id = :restaurant_id', ['NOT IN', 'food_id', [1,2]]], [':restaurant_id' => $postData['resto_id']]);

输出将是你想要的:

DELETE FROM `resto_foods` WHERE (restaurant_id = 1) AND (`food_id` NOT IN (1, 2));
于 2015-12-09T09:56:30.570 回答