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:
$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);
2 replies on “Quick note about deleting records in Symfony/Propel”
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 […]