Add Attribute Manually In Model Which Is Not In Db Table

Hi,

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;


	 }


	 print_r($arr);die;

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.

try




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

            $r=array();

            foreach($projects as $p){

                $r[$p->id]=$p->attributes;

            }

            $q=array();

            foreach($projects as $p){

                $r[$p->id]=$p;

            }

      

            print_r($r);

 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.