Model Mass-Insert


is there a way to create a mass-insert with CActiveRecord Models instead of saving them one-by-one in a loop? Otherwise I have to use plain SQL because its important to have a very good performance.


you can’t do it with AR. version 1.1.14 includes a helper

New method CDbCommandBuilder::createMultipleInsertCommand()

There is now CDbCommandBuilder::createMultipleInsertCommand() to support insertion of multiple records in a single query:


$command=$builder->createMultipleInsertCommand('tbl_post', array(

  array('title' => 'record 1', 'text' => 'text1'),

  array('title' => 'record 2', 'text' => 'text2'),



Ok thank you.