I need to insert multiple ActiveRecord object in Yii,if all of them inserted
$transaction = Yii::app()->db->beginTransaction();
for ($i = 0;$i < 10;$i++){
$model = new Mymodel();
$model->x = $i;
if (!$model->save()){
$transaction->rollback();
break;
}
}
if ($transaction->active)
$transaction->commit();
Now I need to insert all of them in one query,How can I do it during using active record?
A new version of this class
Usage would be:
While not entirely Yii like, it can be made as an extension/component, and is treated like a normal command, so transactions still apply. It would be entirely possible to set this up to utilise parameters rather than string literals in the query, and could also implement checking of null and default values.
Usage would be:
Of course it could be made more elaborate and extended to allow for updates, etc
Hope this helps.