How CGridView write Join query?


I wold like to understand how CGridView write Join query.

For example, I have the following column setting in my gridview

                            array( 'header'=>'Description',  'value'=>'$data->customer->rfor05'),        

                            array( 'header'=>'City',              'value'=>'$data->customer->citf05'),               

in my model, I have definied the following relation:

			'customer' => [self::HAS_ONE, 'ANAFR00F', '','foreignKey' => array('cfoy05'=>'cdes0a')],

where can I find the piece of code in which Yii set the Join condition? I use the logger and I see that a query with a join is executed on the table associated to my model.

Look into my extension:

It is not the CGridView handling the join, but the data provider that has to be set with the right conditions.

The extension helps with join tables and makes the related fields look as native fields in the CGridView.


Its usually in your Model relations array where you define the relationship between models

if any model has following relation,

return array(

		'category' => array(self::BELONGS_TO, 'Category', 'category_id'),

                    'country' => array(self::BELONGS_TO, 'Country', 'country_id'),

                    'city' => array(self::BELONGS_TO, 'City', 'city_id'),


here it says country/city/category has relational data like $model->country->Name or $model->city->name or $model->category->title.