Joining a Yii Model Relationship (HAS_ONE)

I want the basic syntax for relationships and their parameters

I need this clarification

  • Difference between BELONGS_TO and HAS_ONE?
  • I want to use a relation in CGridView (this relation refers to another table element as a foreign key) For example, I have three tables.
  • Messenger
  • Userlogin
  • Userprofile

I am in the Messenger Admin Grid I have a primary key for the UserLogin table This userlogin has a user profile Primary key Now I want to access the userProfile field in my grid

i am already trying (through) in relation to how

him in the messenger model

    'relationeg'=>array(self::HAS_ONE,'Userprofile',array('user_id'=>'id'),'through'=>'user'),
'user'=>array(self::BELONGS_TO, 'UserLogin','user_id'),

I access this in my grid

    .....
    ....
array(
    'name'=>'message_by',
    'value'=>'$data->relationeg->username'
),
....
...

But I got the wrong data, which is completely different from the write key of the base table

I have doubts about this line

'relationeg'=>array(self::HAS_ONE,'Userprofile',array('user_id'=>'id'),'through'=>'user'),

self:: HAS_ONE ? where ,

+1
1

: BELONGS_TO , ; .

: HAS_ONE , - , ; .

, PARENT , , CHILD , "" , .

, CHILD BELONGS_TO - HAS_ONE .

+1

All Articles