$array = array(1,2,3);
foreach($array as $id) {
//fetch model if it exists
$model = ModelA->model()->findByPk($id);
//if no record found
if(is_null($model)) {
$model = new modelA;
}
$model->someAttribute = someValue;
$model->save();
unset($model);
}
if no record is found the code should create a new instance of modelA and INSERT it
this works on the first iteration of the loop
but after that
$model gets populated by the values saved on the first iteration
I tried to add $model->isNewRecord = true instead of unsetting $model
but this does not work either
can someone explain what I should be doing to achieve this ?