title: Yii framework: Using data from related Active Record models for searching
body: <p>Yii 1.1 application development Cookbook explain a method for using data from related Active Record Models for searching the related models as well. This method is explained in page number 193 and 194. i have tried to integrate this method in to my application but it does not work. could anybody explain me whether this feature is still available in Yii framework version 1.1.8 </p>
  
  <p>At this location also i could find comments for searching data form related active record models. But it also does not work. 
  <a href="http://www.yiiframework.com/doc/api/1.1/CDbCriteria" rel="nofollow noreferrer">http://www.yiiframework.com/doc/api/1.1/CDbCriteria</a></p>
  
  <p>I have order table and user table</p>
  
  <p>Order table and User table has One to many Relation.</p>
  
  <p>User has many orders and order has exactly one user. </p>
  
  <p>So , i am editing following CDbCriterial to include user tables name and email field in to Order tables search entries. </p>
  
  <p>Order table has following relations</p>
  
  <pre><code>public function relations()
  {
      // NOTE: you may need to adjust the relation name and the related
      // class name for the relations automatically generated below.
      return array(
          'comments' =&gt; array(self::HAS_MANY, 'Comment', 'order_id'),
          'user' =&gt; array(self::BELONGS_TO, 'User', 'user_id'),
          'orderstatus' =&gt; array(self::BELONGS_TO, 'Orderstatus', 'orderstatus_id'),
          'commentCount' =&gt; array(self::STAT, 'Comment' , 'order_id')
      );
  }
  </code></pre>
  
  <p>This is the search/filter conditions with user table's name filed included </p>
  
  <pre><code>public function search()
      {
          // Warning: Please modify the following code to remove attributes that
          // should not be searched.
  
          $criteria=new CDbCriteria;
  
          $criteria-&gt;compare('id',$this-&gt;id);
          $criteria-&gt;compare('order_create_date',$this-&gt;order_create_date,true);
          $criteria-&gt;compare('price',$this-&gt;price,true);
          $criteria-&gt;compare('bank_account_number',$this-&gt;bank_account_number,true);
          $criteria-&gt;compare('hardwaredetail_Id',$this-&gt;hardwaredetail_Id);
          $criteria-&gt;compare('user_id',$this-&gt;user_id);
          $criteria-&gt;compare('order_update_date',$this-&gt;order_update_date,true);
          $criteria-&gt;compare('is_received',$this-&gt;is_received);
          $criteria-&gt;compare('order_received_date',$this-&gt;order_received_date,true);
          $criteria-&gt;compare('is_notify_by_email',$this-&gt;is_notify_by_email);
          $criteria-&gt;compare('warehouse_offered_price',$this-&gt;warehouse_offered_price,true);
          $criteria-&gt;compare('warehouse_offered_price_date',$this-&gt;warehouse_offered_price_date,true);
          $criteria-&gt;compare('orderstatus_id',$this-&gt;orderstatus_id);
          $criteria-&gt;together = true; 
          $criteria-&gt;with = array('user');
          $criteria-&gt;compare('user.name',$this-&gt;user,true);
          //$criteria-&gt;compare('user.name',$this-&gt;user-&gt;name);
          return new CActiveDataProvider($this, array(
              'criteria'=&gt;$criteria,
          ));
      }
  </code></pre>
  
  <p>and Order admin page is edited to display the name filed as follows </p>
  
  <pre><code>&lt;?php $this-&gt;widget('zii.widgets.grid.CGridView', array(
      'id'=&gt;'order-grid',
      'dataProvider'=&gt;$model-&gt;search(),
      //'filter'=&gt;$model,
      'columns'=&gt;array(
          'id',
          'order_create_date',
          'price',
          'bank_account_number',
          array(
              'name'=&gt;'user',
              'value'=&gt;'$data-&gt;user-&gt;name'
          ),
         ),
  ));
  </code></pre>
  
  <p>Error message returned </p>
  
  <p><img src="https://i.stack.imgur.com/rpkTN.png" alt="enter image description here"></p>
  
  <p>After solving the id column ambiguity problem by applying the solution that thaddeusmt gave i have faced with the following error message. </p>
  
  <p><img src="https://i.stack.imgur.com/X8i55.png" alt="enter image description here">  </p>
  
  <p>Thanks in advance for any help</p>