0

I have so many fields in my custom table. When, I update records at that time, I save records as like below code :

$myModel->load($id);
$myModel->setData('field_1',$field_1);
$myModel->setData('field_2',$field_2);
$myModel->setData('field_3',$field_3);
$myModel->setData('field_4',$field_4);
$myModel->setData('field_5',$field_5);
$myModel->setData('field_6',$field_6);
$myModel->save();

But, I don't want to use setData() multiple times. Then, how to save records just using one time setData().

Anyone know about this?

0

You need to add your primary key field also in array and add that field value in array. Then, add array in setData() like this way :

$array['id'] = $id; //add your primary key field of the table
$array['field_1'] = $field_1;
$array['field_2'] = $field_2;
$array['field_3'] = $field_3;
$array['field_4'] = $field_4;
$array['field_5'] = $field_5;
$array['field_6'] = $field_6;
$myModel->setData($array);
$myModel->save();

Hope, It will useful for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy