$criteria = new CDbCriteria();
$criteria->distinct = true;
$criteria->addCondition('sender_id = :sender');
$criteria->select('recipient_id');
$criteria->params = array(':sender' => Yii::app()->getUser()->getId());
$userMessages = Messages::model()->findAll($criteria);
$uniqRecipients = array();
foreach($userMessages as $model)
$uniqRecipients[] = $model->recipient_id;
//in Users
array(self::BELONGS_TO, 'UserRole', 'role_id'),
//in UserRole
array(self::HAS_MANY, 'Users', 'role_id'),