Nov 24
Digg
Stumbleupon
Technorati
Delicious

Quick note about deleting records in Symfony/Propel

Just a quick note about deleting records in Symfony/Propel.
I’ve tested it both in symfony 1.2.x and symfony 1.0.x and got the same result.
So when you try to delete all records from table this way:

1
2
$c = new Criteria();
$rs = TablePeer::doDelete($c);

nothing happens but when I tried to add any dummy criteria to it like this:

1
2
3
$c = new Criteria();
$c->add(TablePeer::ID, 0, Criteria::GREATER_THAN);
$rs = TablePeer::doDelete($c);

it deleted all records like expected. Maybe I’ve missed something but looks like not logical to me.

If you want to try it yourselves here is sample of batch script:

1
2
3
4
5
6
7
8
9
  require_once(dirname(__FILE__) . '/../config/ProjectConfiguration.class.php');
  $configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'dev', true);
  sfContext::createInstance($configuration);
 
  $databaseManager = new sfDatabaseManager($configuration);
  $databaseManager->loadConfiguration();
 
  $c = new Criteria();
  $rs = TablePeer::doDelete($c);

Author: symfonian

2 Comments

Massimiliano Arione
November 25, 2009

IMHO it’s better to always use a criteria do select the objects you need, and THEN cycle to delete them. In this way, you’re able to use event listeners.

[…] Quick note about deleting records in Symfony/Propel […]

Comments RSS TrackBack Identifier URI

Leave a comment