I am using CDbCommandBuilder::createMultipleInsertCommand() to create a multiple insert CDbCommand. But how can I run validation before saving it?
For single insert commands, the validation is done inside save() method (I think).
Code:
// Controller
if (isset($_POST[‘ProductBrand’])) {
[indent]$model->attributes = $_POST[‘ProductBrand’];[/indent]
[indent]if ($model->saveRows())[/indent]
[indent][indent]$this->redirect(array(‘indexBrand’));[/indent][/indent]
}
// Model
public function saveRows()
{
[indent]$builder = Yii::app()->db->schema->commandBuilder;
$names = explode(’, ', $this->attributes[‘name’]);
$type_id = $this->attributes[‘type_id’];
$attributes = array();
foreach ($names as $name) :
$attributes[] = array(‘name’ => $name, ‘type_id’ => $type_id);
endforeach;
$command = $builder->createMultipleInsertCommand(
‘vwa_product_brand’, $attributes);
if ($command->execute()) :
[indent]return TRUE;[/indent]
endif;
return FALSE;[/indent]
}
Any help is appreciated.