relations in CActiveDataProvider

Hello i would like to know why this isnot working and what i can do differently to make it work :)

i want to display a list of websites thats only made by the loggedin user…

my relation :

‘websiteUsers’ => array(self::HAS_MANY, ‘WebsiteUser’, ‘websiteId’),

my search function

public function search()


	// Warning: Please modify the following code to remove attributes that

	// should not be searched.


	$criteria=new CDbCriteria;




	if (Yii::app()->user->getState("level") !="admin"){

        $criteria->with = 'websiteUsers';    	

    	$criteria->compare('userId', Yii::app()->user->getId());



	return new CActiveDataProvider($this, array(



it says userId doesnot exist…???

I am new to yii and would really like to know this txs in advance.

CDbCommand faalde tijdens het uitvoeren van volgend SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘userId’ in ‘where clause’. The SQL statement executed was: SELECT AS t0_c0, t.url AS t0_c1, t.code AS t0_c2 FROM website t WHERE (userId=:ycp0) LIMIT 10

Try together attribute for your criteria. For example:

if (Yii::app()->user->getState("level") != "admin"){

  $criteria->with = array(

    'websiteUsers' => array(

      'condition' => 'userId = :userId',

      'params' => array(':userId' => Yii::app()->user->id)


  $criteria->together = true; 

  $criteria->addCondition('websiteUsers.userId IS NOT NULL');