I have three database tables called Milestones, Log and User.
The Milestones table has a unique id attribute and a Log_id attribute
which points to a single record in the Log table.
The Log table has a unique id attribute and a Dir_id attribute
which points to a single record in the User table.
The User table has a unique id attribute and a loginName attribute.
I have created a milestones view containing a CGridView that has a Director column
defined as follows:
array(
'name'=>'dir_search',
'value'=>'$data->log->dir->loginName',
),
log is defined as a relation in the Milestones model (self::BELONGS_TO, ‘Log’, ‘Log_id’) and
dir is defined as a relation in the Log model (self::BELONGS_TO, ‘User’, ‘Dir_id’)
The Milestones model has a dir_search attribute for filtering and a searchuser function
which populates a CActiveDataProvider which is the dataProvider in the CGridView.
The searchuser function contains the following criteria:
$criteria->compare('log.dir.loginName', $this->dir_search, true );
The CActiveDataProvider returned by the searchuser function has the following entry in its sort array:
'dir_search'=>array(
'asc'=>'log.dir.loginName',
'desc'=>'log.dir.loginName DESC',
),
The Log model also has a dir_search attribute for filtering and a search function
which populates and returns a CActiveDataProvider.
The Log model search function contains the following criteria:
$criteria->compare('dir.loginName',$this->dir_search);
The CActiveDataProvider returned by the Log model search function has the following entry in its sort array:
'dir_search'=>array(
'asc'=>'dir.loginName',
'desc'=>'dir.loginName DESC',
The Director column is populated correctly for each Milestones record in the grid.
But the sort and the filter functions for the Director column in the view are not working.
Clicking on the Director column heading to sort the column results in a popup with SQL error
"Unknown column ‘log.dir.loginName’ in ‘order clause’.
Entering a value in the filter box under the Director column heading results in a similar popup with SQL error
"Unknown column ‘log.dir.loginName’ in ‘where clause’.
I suspect the problem is due to the two-table, indirect reference to the loginName attribute.
How do I fix these references so that the sorting and filtering of the Director column will function correctly?