i use relations and join two table and execute the query,,but gets error

i used relations to join two tables for retreiving results from both but i get error when both the table contains same field name…i get error as the field name is ambiguous

You should declare an alias for the related table… yo can do it in the relations() method.

can u explain me further plz

Yes, may be you have a model named Model1 and another model named Model2.

Supose that Model1 belongs to Model2, then in your Model1 model you have the following method:

class Model1 extends CActiveRecord


   ///... other code


   public function relations(){

      return array(

         'model2'=>array(self::BELONGS_TO,'Model2','model1FK', 'alias'=>'Model2'), 

         // Supose that model1FK is the foreing key in your database.

         // Take a look at the 'alias' element of the array, it's good to maintain the model name, but you can name it whatever you want.



   ///... other code


Is this enough?

You may also refer to the Active Record:[link]http://www.yiiframew…ide/database.ar[/link] and to the Relational Active Record [link]http://www.yiiframew…de/database.arr[/link] in the guide.

yes i got it…thanks…