Doctrine - insert multiple rows with just one save()

前端 未结 5 1246
死守一世寂寞
死守一世寂寞 2020-12-08 21:03

How do I insert multiple rows into table calling save() method once in Doctrine?

5条回答
  •  -上瘾入骨i
    2020-12-08 21:34

    Here another solution ,tested on Doctrine 1.2. No need to save each records, the flush() automatically finds out all the unsaved instances and saves them all.

    $row = new \My_Doctrine_Record();
    $row->name = 'aaa';
    $row->approved = 1;
    
    /// ...
    
    $row = new \My_Doctrine_Record();
    $row->name = 'val';
    $row->approved = 'bbb';
    
    Doctrine_Manager::connection()->flush();
    

提交回复
热议问题