Greetings all,
I’ve spent two days on this and can’t figure it out. I’ve also searched forums and can’t find anything that details exactly what I need. I’m very new to yii, so the explanations that are close aren’t quite working for me.
I want to display a child of a child in cgridview. I have a table called Project that has a field called KeyTasks. This field is meant to hold the key of a task (it’s the next task due). The tables layout like this:
table Project
Project.KeyProject (primary)
Project.ProjectName
Project.KeyTasks
table ProjectTasks
ProjectTasks.KeyTasks (primary)
ProjectTasks.KeyTask
table ProjectTask (this is a lookup table, holding the descriptions of the tasks)
ProjectTask.KeyTask (primary)
ProjectTask.Description
In the grid, I want to show the Project.ProjectName, ProjectTask.Description, which links to ProjectTasks. Using relations I can show ProjectTasks.KeyTasks or ProjectTasks.KeyTask no problem, but I want the child of ProjectTasks, not the child of Project, so I can show ProjectTask.Description.
Make sense? Here’s the not-working code:
Project.php model:
Relations:
return array(
'keyTaskStatus' => array(self::BELONGS_TO, 'ProjectTasks', 'KeyTaskStatus'),
'keyPaymentType' => array(self::BELONGS_TO, 'PaymentType', 'KeyPaymentType'),
'keyCustomer' => array(self::BELONGS_TO, 'Customer', 'KeyCustomer'),
'keyDocument' => array(self::BELONGS_TO, 'Documents', 'KeyDocument'),
'keyEmployee' => array(self::BELONGS_TO, 'Employee', 'KeyEmployee'),
'keyProjectHealth' => array(self::BELONGS_TO, 'ProjectHealth', 'KeyProjectHealth'),
'did' => array(self::BELONGS_TO, 'Domain', 'DID'),
);
Search:
$criteria=new CDbCriteria;
// this is so those two tables are included in the SQL generated:
$criteria->with = array('keyCustomer', 'keyEmployee');
$criteria->compare('KeyProject',$this->KeyProject);
$criteria->compare('ProjectName',$this->ProjectName,true);
$criteria->compare('keyCustomer.LastName',$this->CustomerLastName,true);
$criteria->compare('keyEmployee.LastName',$this->SalespersonLastName,true);
$criteria->compare('keyAddress.Street1',$this->CustomerAddress,true);
$criteria->compare('KeyDocument',$this->KeyDocument);
$criteria->compare('KeyPaymentType',$this->KeyPaymentType);
$criteria->compare('KeyProjectHealth',$this->KeyProjectHealth);
Grid:
<?php $this->widget(‘zii.widgets.grid.CGridView’, array(
'id'=>'project-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array(
'name'=>'KeyProject',
'htmlOptions'=>array('width'=>'40px'),
),
'ProjectName',
'CustomerLastName',
array(
'name'=>'CustomerAddress',
'filter'=>false,
),
'SalespersonLastName',
'KeyTaskStatus',
array(
'name'=>'StatusDescription',
'value'=>'KeyTaskStatus->KeyTask->Description' ,
),
'KeyDocument',
array(
'class'=>'CButtonColumn',
),
),
)); ?>
Thanks in advance for any advice!!