Call to undefined method stdClass::save()

I have two tables: tbl_message and tbl_messageto.

When message is posted, the record at first saves in tbl_message [assume that the record’s id is 3 ] after the same record must be inserted into tbl_messageto.

I did but in the table ‘tbl_messageto’ only once record is posted. Is there any technique so that the record can be inserted twice??

I get an error Call to undefined method stdClass::save()

My code is :

    	$model = new Message;

		$modelMSGTo = new Messageto;

		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);



			$transaction = $model->dbConnection->beginTransaction();




				// access member id

				$model->authorId = Yii::app()->user->id;


				// first step 



					$modelMSGTo->messageId = $model->messageId;

					$modelMSGTo->memberId =$model->toAddress;

					$modelMSGTo->authorId =$model->authorId;

					$modelMSGTo->isNew =(int)1;

					$modelMSGTo->isUnread = (int)1;

					$modelMSGTo->messageStatusId = (int)1;


           		// second step




                   		*  now every field should be same except  memberId 

                      	*   now memberId 's value should be current authorId


						//$modelMSGTo->messageId = $model->messageId;

						$modelMSGTo->memberId =$model->authorId;

						//$modelMSGTo->authorId =$model->authorId;

						//$modelMSGTo->isNew =(int)1;

						//$modelMSGTo->isUnread = (int)1;

						//$modelMSGTo->messageStatusId = (int)1;








						throw new CException($modelMSGTo->getErrors());





					throw new CException($model->getErrors());






			catch(CException $er){







save() checks if the record is new to make an INSERT… and if it’s not (your case because it’s already saved) it make an UPDATE…

Before the second save() you need to tell Yii that this is a new record… you can do it with


:rolleyes:Ya it worked! Thank you mdomba for your help.