title: Yii with join using CDbCriteria and CActiveDataProvider with custom Search
body: <p>Hi I am using Yii to create an Application</p>
  
  <p>I have modified the search() in model and I have come up with a problem.</p>
  
  <p>Users can log in as admins, managers, clients</p>
  
  <p>When a user is logged as a manager, he can view clients only from the store they both belong. So far so good, I've managed to accomplish that. </p>
  
  <p>Now the problem is when I try to prevent managers from viewing other managers from the same store (and therefore edit each other's accounts) in CGridView. </p>
  
  <p>The relations</p>
  
  <pre><code>/**
   * @return array relational rules.
   */
  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(
          'authitems' =&gt; array(self::MANY_MANY, 'Authassignment', 'authassignment(userid, itemname)'),
          'additionalContacts' =&gt; array(self::HAS_MANY, 'AdditionalContact', 'Client_Id'),
          'store' =&gt; array(self::BELONGS_TO, 'Store', 'Store_Id'),
          'user' =&gt; array(self::BELONGS_TO, 'User', 'User_Id'),
          'genericPoints' =&gt; array(self::HAS_MANY, 'GenericPoint', 'Client_Id'),
      );
  }
  </code></pre>
  
  <p>The Custom model search</p>
  
  <pre><code>public function searchCustom()
  {
      // Warning: Please modify the following code to remove attributes that
      // should not be searched.
  
      $criteria=new CDbCriteria;
      $criteria-&gt;addCondition('t.id !='.$this-&gt;id);
      $criteria-&gt;compare('t.Created',$this-&gt;Created,true);
      $criteria-&gt;compare('t.Updated',$this-&gt;Updated,true);
      $criteria-&gt;compare('t.Discount',$this-&gt;Discount,true);
      $criteria-&gt;compare('t.Discount_Type',$this-&gt;Discount_Type,true);
      $criteria-&gt;addCondition('t.Store_Id ='.$this-&gt;Store_Id);
  
      //$criteria-&gt;addCondition('t.id !='.$this-&gt;id);
  
      //GET FIELDS FROM USER IN SEARCH
  
      $criteria-&gt;with=array('user');
      $criteria-&gt;compare('user.id',$this-&gt;User_Id,true);
      $criteria-&gt;compare('user.First_Name',$this-&gt;First_Name,true);
      $criteria-&gt;compare('user.Last_Name',$this-&gt;Last_Name,true);
      $criteria-&gt;compare('user.Username',$this-&gt;Username,true);
      $criteria-&gt;compare('user.Email',$this-&gt;Email,true);
      $criteria-&gt;addCondition('user.Status = 1');
  
      $criteria-&gt;with=array('authitems');
      $criteria-&gt;compare('authitems.userid',$this-&gt;id,false);
      $criteria-&gt;compare('authitems.itemname','client',false);
  
      $criteria-&gt;together = true;
  
      $criteria-&gt;order = 't.Created DESC';
      return new CActiveDataProvider($this, array(
              'criteria'=&gt;$criteria,
      ));
  }
  </code></pre>
  
  <p>And this the error I am getting</p>
  
  <pre><code>CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'user.Status' in 'where clause'. The SQL statement executed was: SELECT COUNT(DISTINCT `t`.`id`) FROM `client` `t` LEFT OUTER JOIN `authassignment` `authitems_authitems` ON (`t`.`id`=`authitems_authitems`.`userid`) LEFT OUTER JOIN `authassignment` `authitems` ON (`authitems`.`itemname`=`authitems_authitems`.`itemname`) WHERE (((((t.id !=2) AND (t.Store_Id =1)) AND (user.Status = 1)) AND (authitems.userid=:ycp0)) AND (authitems.itemname=:ycp1))
  </code></pre>
  
  <p>I know it has something to do with the relations the gii set up for me but I can't pinpoint it.</p>
  
  <p>Perhaps authitems' MANY_MANY relation stops the user relation from loading?</p>