serg tch Thu May 09 15:56:27 -0400 2013

Subject: mass delete

From this link http://www.phpactiverecord.xyz/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 already spent 3 days trying to figure that out and searching everywhere online with no luck. Would really appreciate your input! THANK YOU IN ADVANCE!!!


Sachin Parmar Tue May 14 02:25:52 -0400 2013

please use following coding
Model::delete_all(array('conditions' => array('date < ? and category = ? ', '2012-01-01 00:00:00', 'journal')));
Just enjoy ;)

serg tch Tue May 14 16:16:03 -0400 2013

It gives an error:
Fatal error: Uncaught exception 'ActiveRecord\ActiveRecordException' with message 'Call to undefined method: delete_all' ...............

Any ideas?

serg tch Tue May 14 16:49:13 -0400 2013

Had to download the nightly build to work. For some reason this didn't work with the stable build.
Thank you!

serg tch Tue May 14 19:32:10 -0400 2013

Any idea how to count how many were affected (deleted)?

(1-4/4)