Multiple users linking to model

Hello I am a bit new to Yii,

So far i am pretty impressed its so easy to work with and does so much, I am just stuck on a couple of things…

I have a single users table with multiple users in it each of a different type e.g admin and rep, I have related them to my Order model via within the relations function


 'rep' => array(self::HAS_ONE, 'User', 'user_id'), 'admin' => array(self::HAS_ONE, 'User', 'user_id'),

But when i try to display them in a list with all the other orders using


$rep=$data->rep;

echo CHtml::encode($rep->first_name.' '.$rep->last_name); 

It will only display the names of the first instance of the user.

I am right in just trying to use the one table for all users?

Maybe its something silly.

Thanks for any help,

From what i can understand you have the same relation with different names … Why?

I don’t exactly get your use-case but maybe you need a HAS_MANY relationship?

Thanks for replying.

Sorry i didn’t really explain it that well, Basically i have a Order table with admin_id and a rep_id where both of these are users, should i be relating them to these? i did try changing to user_id to these but it just says


Unknown column 'rep.rep_id' in 'where clause'

. I have put the relations in the Order model - this is correct?

I did try HAS_MANY but it didn’t change it :confused:

Fixed it now :-). Changed it from HAS_ONE to BELONGS_TO works fine now