Get Data From Other Table

Im’ trying to get data from table name user_covers, model name: UserCovers by this command:


$model = UserCovers::model()->findByAttributes(array('userid'=>$_POST['useridd'], 'type'=>$_POST['types']));

And get id in order to insert into table name photos, model name: Photos by command:


$photo->user_coverid = $model->id

It works at first time. But now I’ve just found out that the code doesn’t work with new user (users register after the code was updated), just works with old users.

I can’t figure out the problem.

Hi Qian Hwee

Save the model before you get the id


$model->save();

$photo->user_coverid = $model->id

Thank you so much alirz23. It works exactly as you said.