Reputation: 9
From this link http://www.phpactiverecord.org/projects/main/wiki/Basic_CRUD I got the following:
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
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. So my question is HOW can I implement COMPARISON operator into that query with the date?
I've searched everywhere online and can't find the answer anywhere. Would really appreciate your input! THANK YOU IN ADVANCE!!!
Upvotes: 1
Views: 1849
Reputation: 21
delete_all did not work in my case. You can find another way here
# MASSIVE DELETE
# Model::table()->delete(WhereToDelete);
Post::table()->delete(array('id' => array(5, 9, 26, 30));
Upvotes: 0
Reputation: 1844
Try this:
http://www.phpactiverecord.org/docs/ActiveRecord/Model#methoddelete_all
YourModel::delete_all(array('conditions' => array('date >= ? AND category <= ?', $thedate,$cateogry)));
Upvotes: 2