Perform a value check in many to many relation

I have many to many relation between user and course tables (having third table for this user_course)

so If I want to check whether a user register in a course then what is the best method to do it in yii

I know I can do it by creating an extra model for user_course table and can do something like this

$userCourse = UserCourse::model()->findByAttributes(array(

‘userId’=>$userId,

‘courseId’=>$courseId,

));

if ($userCourse != null)

echo ‘User registered’;

else

echo ‘User not registered’;

But is there any other method so that I can skip the creation of that extra model ?

Can I do something like this isset($course->users->findByPk($userId)) ?

Take a look at www.yiiframework.com/extension/giix/.

Happy coding.