Add Attribute Manually In Model Which Is Not In Db Table


Can anyone tell me how can i add a new attribute which is not in db table from controller.Actually i am using ar relation

and below is my controller code.

$restaurants = $model->findAll($condition);

	 $arr = array();

	 foreach($restaurants as $t)


	   $arr[$t->id] = $t->attributes;



in above in foreach with “$t->merchants->name1;” this i can able to get the relative merchant name but can’t set in the

$arr[$t->id] array as $t attribute.


            $projects=  Projects::model()->findAll();


            foreach($projects as $p){




            foreach($projects as $p){





 echo   $r['17']->name.'<br />';

working for me…

Hi Sujoy,

An relation like ‘merchants’ is not an attribute of Restaurant AR object. It’s another AR object (or an array of AR objects).

But, in the first place, why do you have to make another array when you have already retrieved an array of AR objects? What do you want to do with that array?

I think you can do whatever you want with the array of AR objects.