简体   繁体   English

如何使用比较运算符在PHP Activerecord中进行大规模删除

[英]How to Massive Delete in PHP Activerecord with comparison operators

From this link http://www.phpactiverecord.org/projects/main/wiki/Basic_CRUD I got the following: 通过此链接http://www.phpactiverecord.org/projects/main/wiki/Basic_CRUD,我得到了以下内容:

6 # MASSIVE DELETE
7 # Model::table()->delete(WhereToDelete);
8 Post::table()->delete(array('id' => array(5, 9, 26, 30));
9 # DELETE FROM `posts` WHERE id IN (5, 9, 26, 30)

However, I need to delete from a table WHERE DATE is less than 2012-01-01 00:00:00 AND where CATEGORY equal to JOURNAL 但是,我需要从表中删除WHERE DATE小于2012-01-01 00:00:00并且其中CATEGORY等于JOURNAL

The following code does NOT work: 以下代码不起作用:

Model::table()->delete(array('date'=>'<2012-01-01 00:00:00','category'=>'journal'));

If I leave: 如果我离开:

Model::table()->delete(array('category'=>'journal'));

it deletes only the WHERE category equals to journal. 它仅删除等于日记的WHERE类别。 So my question is HOW can I implement COMPARISON operator into that query with the date? 所以我的问题是我该如何在日期查询中实现COMPARISON运算符?

I've searched everywhere online and can't find the answer anywhere. 我在网上到处搜索,在任何地方都找不到答案。 Would really appreciate your input! 非常感谢您的投入! THANK YOU IN ADVANCE!!! 先感谢您!!!

Try this: 尝试这个:

http://www.phpactiverecord.org/docs/ActiveRecord/Model#methoddelete_all http://www.phpactiverecord.org/docs/ActiveRecord/Model#methoddelete_all

YourModel::delete_all(array('conditions' => array('date >= ? AND category <= ?', $thedate,$cateogry)));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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