relations

how to write relation between User and Type

  1. when User has got type_id

  2. and Type has got type_id

and so

  1. User.type_id = Type.type_id

NOT

  1. User.type_id = Type.id

if it was like in 4. it would be

‘usertype’ => array(self::BELONGS_TO,‘Type’,‘type_id’),

can not figure out how to use Type.type_id instead

any ideas? thx!

Yii matches belongs_to to the primary key of the other table. So you’re saying type_id is not the primary key? If it’s not then User doesn’t belong to Type.

What is the primary key of the Type table? How do they relate (one to one, one to many, …)?

hi

thank you for message,

meantime I dug out thread which gives answer to my question

http://www.yiiframework.com/forum/index.php?/topic/4148-ar-relation-foreign-key/

thx!