Doctrine - insert multiple rows with just one save()

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

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

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-08 21:49

    Add each record to a Doctrine_Collection the call save() on the collection object.

    $collection = new Doctrine_Collection('tablename');
    $collection->add($record1);
    $collection->add($record2);
    $collection->add($record3);
    $collection->add($record4);
    $collection->save();
    

    This only works if all the records are for the same table. Otherwise you're out of luck.

提交回复
热议问题