jeudi 25 mai 2017

Batch Insert yii2 from checkbox

Basically I have tow models in one form, and I have an array value from checkbox. This is my form :

Model 1

$dataConditionContainer = ArrayHelper::map(ItemConditionIr::find()->all(), 'id', 'nama_condition');
echo $form->field($modelLinkItemConditionIrToIr, 'condition_id')->label("Container")->inline()->checkBoxList($dataConditionContainer);

Model2

<?= $form->field($modelInspectionReport, 'vehicle_no')->textInput(['maxlength' => true]) ?>

Now, from Model 1 that interprated by checkbox give me an array like this :

Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
)

I want to insert them using batch insert, but this array need a value from model2 primary key like $inspectionReport = $modelInspectionReport->id.

Now How to make a batch insert ? I know like this :

 $connection->createCommand()->batchInsert('link_item_condition_ir_to_ir',
       ['inspection_id', 'condition_id'], checkboxarraysuitable)->execute();

Is yii2 provide this ?

Please advise.




Aucun commentaire:

Enregistrer un commentaire