Symfony 1.4 improve doctrine save() method

前端 未结 1 2027
抹茶落季
抹茶落季 2021-01-15 23:16

I have 500 entries in my db. In my backend I have action. For example:

 public function executeMyAction(sfWebRequest $request) {

 // Get some data from tabl         


        
相关标签:
1条回答
  • 2021-01-15 23:57

    Save each record instead of a collection

    $templates = Doctrine_Core::getTable('SeoTemplates')->findOneByEntity('training');
    $trainings = Doctrine::getTable('Training')->getTraining();
    foreach ($trainings as $training) {
       $training->setSomeValue1('some_data');
       $training->setSomeValue2('some_data');
       $training->setSomeValue2('some_data');
       $training->save();
    }
    

    or use Doctrine to update the records using a query

    $q = Doctrine_Query::create()
       ->update('TABLE')
       ->set($val1, '?', $val1)
       ->set($val2, '?', $val2)
       ->set($val3, '?', $val3)
       ->where('id = ?', $id)
       ->execute();
    
    0 讨论(0)
提交回复
热议问题