Self Join Or Self Relation

Hello friends,

I want to implement self join.

I have one table company






groups is foreign key which is primary key (company id ) from same table.

My Problem is in CGridview i want to display a groups (parent company name.) .


Hello friends i found Solution,

1. Company.php <— My model

public function relations()


		return array(

                  "Group"    =>array(self::BELONGS_TO,"Company","groups")



2. Added one variable for search

public $group_name;

3. Add in rules

array('company_id, name, notes, is_delete,[b]group_name[/b]', 'safe', 'on'=>'search'),

4. In search() method set criteria

$criteria->with = array("Group");

        $criteria->compare("",  $this->group_name, true);

5. In admin.php view file add below column

array("name"    => "group_name",

              "value"   =>'$data->Group->name'