/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'test', false); $databaseManager = new sfDatabaseManager($configuration); $models = Doctrine::getLoadedModels(); foreach ($models as $model) { $connections[Doctrine::getTable($model)->getConnection()->getName()][] = $model; } Doctrine_Manager::connection()->execute('SET FOREIGN_KEY_CHECKS = 0'); foreach ($connections as $connection => $models) { $models = Doctrine_Manager::getInstance()->getConnection($connection)->unitOfWork->buildFlushTree($models); foreach ($models as $model) { Doctrine::getTable($model)->getConnection()->getDbh()->query("SET FOREIGN_KEY_CHECKS=0;"); Doctrine::getTable($model)->createQuery()->delete()->execute(); } } Doctrine_Core::loadData(sfConfig::get('sf_test_dir').'/fixtures'); Doctrine_Manager::connection()->execute('SET FOREIGN_KEY_CHECKS = 1');