Note that there are some explanatory texts on larger screens.

plurals
  1. POyii 'through' relation search
    primarykey
    data
    text
    <p>I have the following tables.</p> <pre><code>User: --------- id&lt;br&gt; firstName Project: --------- id&lt;br&gt; Name StaffingManager --------------- id&lt;br&gt; User_id(FK)&lt;br&gt; Total_Staff&lt;br&gt; StaffingProjectMonth ----------------------- id&lt;br&gt; Project_id(FK)&lt;br&gt; StaffingManager_id(FK)&lt;br&gt; </code></pre> <p>I want to define the relations in StaffingProjectMonth model</p> <p><em>This is the default relation defined by YII using gii</em></p> <pre><code>public function relations() { return array( 'project' =&gt; array(self::BELONGS_TO, 'Project', 'Project_id'), 'staffingManager' =&gt; array(self::BELONGS_TO, 'StaffingManager', 'StaffingManager_id'), ); } </code></pre> <p>I was able to get the ProjectName and search by ProjectName.</p> <p>I want to get the UserfirstName and search by that.</p> <p>I defined the relation this way.</p> <pre><code>return array( 'project' =&gt; array(self::BELONGS_TO, 'Project', 'Project_id'), 'staffingmanager' =&gt; array(self::BELONGS_TO, 'StaffingManager', 'StaffingManager_id'), 'user'=&gt; array(self::HAS_MANY,'User',array('User_id'=&gt;'id'),'through'=&gt;'staffingmanager' ), ); </code></pre> <p>and in search method I did this:</p> <pre><code>$criteria-&gt;with = array('project','user'); //$criteria-&gt;compare('id',$this-&gt;id); $criteria-&gt;compare('Name',$this-&gt;Project_id,true); $criteria-&gt;compare('firstName',$this-&gt;StaffingManager_id,true); </code></pre> <p>and in the view:</p> <pre><code>$this-&gt;widget('zii.widgets.grid.CGridView', array( 'id'=&gt;'staffing-project-month-grid', 'dataProvider'=&gt;$model-&gt;search(), 'filter'=&gt;$model, 'columns'=&gt;array( // 'id', array('name'=&gt;'Project_id','header'=&gt;'Project','value'=&gt;'$data-&gt;project-&gt;Name',), array('name'=&gt;'StaffingManager_id','header'=&gt;'User','value'=&gt;'$data-&gt;staffingmanager-&gt;user-&gt;firstName',), .............. </code></pre> <p>only the search by project name works. Able to sess the UserfirstName but unable to search by the firstName. Some wrong in defining relations.</p> <p>Any help is appreciated. Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload