CBDCriteria Relations

Hi

I have the following code:





      $criteria->with = array('tos');

		

		if($sent)	

			$criteria->addCondition('t.from_user_id = '. Yii::app()->user->id);

		else

		{

			$criteria->addCondition('tos.to_user_id = '. Yii::app()->user->id);

		}

		

		return new CActiveDataProvider('YumMessage', array(

				'criteria' => $criteria,

				'pagination' => array(

					'pageSize' => Yum::module()->pageSize,

					),

				)

			);

and the following relation


'tos'=>array(self::HAS_MANY, 'MessagesTos', 'message_id',

in model YumMessage

and the following relation in model MessagesTos


'message' => array(self::BELONGS_TO, 'YumMessage', 'message_id'),

For some reason however, my query above does not work: I’m getting the following error: CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘tos.to_user_id’ in ‘where clause’

I want to select all the messages (YumMessage) where to to_user_id from MessagesTos model is that of the user.

thanks!

any help would be greatly appreciated

I believe you need to also set $criteria->together = true so that it actually joins the data in at that stage.