Posted By

barbelith on 08/30/10


Tagged


Versions (?)

Empty tables and reload data in Doctrine


 / Published in: PHP
 

  1. $configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'test', false);
  2. $databaseManager = new sfDatabaseManager($configuration);
  3.  
  4.  
  5. Doctrine_Core::loadModels(dirname(__FILE__).'/../../../lib/model');
  6.  
  7. $models = Doctrine::getLoadedModels();
  8.  
  9. $connections = array();
  10. foreach ($models as $model) {
  11. $connections[Doctrine::getTable($model)->getConnection()->getName()][] = $model;
  12. }
  13.  
  14. Doctrine_Manager::connection()->execute('SET FOREIGN_KEY_CHECKS = 0');
  15. foreach ($connections as $connection => $models) {
  16. $models = Doctrine_Manager::getInstance()->getConnection($connection)->unitOfWork->buildFlushTree($models);
  17. $models = array_reverse($models);
  18. foreach ($models as $model) {
  19. Doctrine::getTable($model)->getConnection()->getDbh()->query("SET FOREIGN_KEY_CHECKS=0;");
  20. Doctrine::getTable($model)->createQuery()->delete()->execute();
  21. }
  22. }
  23.  
  24. Doctrine_Core::loadData(sfConfig::get('sf_test_dir').'/fixtures');
  25. Doctrine_Manager::connection()->execute('SET FOREIGN_KEY_CHECKS = 1');

Report this snippet  

You need to login to post a comment.