Home > PHP, Symfony 1.3 & 1.4 > Symfony Batch Delete while using Doctrine Soft Delete

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.

  1. Joe
    July 12th, 2010 at 14:08 | #1

    I’m not sure when this was fixed, but I just tested it in 1.4 and SoftDelete did work with a batch delete.

  2. Joe
    July 15th, 2010 at 11:50 | #2

    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

  1. No trackbacks yet.