Problem wth Multiple Insert Queries

Hi All,

I have a form and on submitting the form I am trying to insert two rows in the same table. I am using ActiveRecord for this and may be because of my less knowledge I am having a problem in it.

Whenever i try to insert values it only inserts one row.

The code is given here

  $model = new MachineAlarm;  

  $model->strAlarmName = $criteria;

   $model->intAlarmUpperLimit = $alarmUpperLimit;  

   $model->intAlarmLowerLimit =$alarmLowerLimit;

   $model->strAlarmCriteria = $criteria;

   $model->strMachine_Id = $machineId;

    $model->strAlarmDescription ='Maintenance';

    $model->strAlarmLevel = '1';


                           $model->strAlarmName = $criteria;

               $model->intAlarmUpperLimit = '0';  

               $model->intAlarmLowerLimit =$alarmUpperLimit;

               $model->strAlarmCriteria = $criteria;

               $model->strMachine_Id = $machineId;

               $model->strAlarmDescription ='Critical';

               $model->strAlarmLevel = '2';


As per my understanding it should insert two rows but it is inserting only one row and that too the second portion…

Any help is highly appreciated.


Create Two AR models… $model = new MachineAlarm(); … save(); ----- $model = new MachineAlarm(); and then save again();

On your code, you are just updating the same model after you do the first save()

Will lead to one save followed by one update operation. Try setting isNewRecord=true.

(not tested)


Thanks a lot.

Problem solved…

Will not be repeated in future.That was quite silly on my part


@Antonio Ramirez thank you for method. I have solved my problem.