Doctrine - insert multiple rows with just one save()

Almas Adilbek picture Almas Adilbek · Mar 24, 2011 · Viewed 21.2k times · Source

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

Answer

xzyfer picture xzyfer · Mar 24, 2011

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.