Symfony Batch Delete while using Doctrine Soft Delete
Doctrine Soft Delete is a fabulous method that will set a deleted_at column when the user deletes a record. So it doesn’t really delete the record but timestamps it as deleted.
This offers wonderful functionality to you admin generated app. But there’s a catch!
If you’re using a batch delete you’ll notice that the code uses DQL (Doctrine Query Language) to make the delete and not actually calling the delete() method from the class.
I fixed this quickly by actually time stamping deleted_at field:
$count = Doctrine_Query::create()
->update('myclass')
->set('deleted_at','now()')
->whereIn('id', $ids)
->execute();
Symfony should account for this so that soft delete will work properly with admin generated code.
I’m not sure when this was fixed, but I just tested it in 1.4 and SoftDelete did work with a batch delete.
I found out the reason it worked for me was because I have DQL callbacks enabled:
http://www.doctrine-project.org/documentation/manual/1_1/schema-files/behaviors:core-behaviors:softdelete