Hello All,
I am newbie to yii and trying to learning it.
I am little bit confused to use relations,
in my application i have 3 tables
users :
id
username
user_profiles:
id
user_id (FK users(id))
first_name
last_name
Album:
id
user_id (FK users(id))
album_name
album_code
In grid view of "Album" i am going to display
user_name , album_code, album_name
in this case how to use relation. please explain me
Thank you
rupsk1607
(Webin2015)
2
In ur UserProfileModel:
public function getUser()
{
return $this->hasOne(User::className(), ['id' => 'user_id']);
}
In ur AlbumModel:
public function getUser()
{
return $this->hasOne(User::className(), ['id' => 'user_id']);
}
In your albumgrid for username
[
'user.user_name',
],
**Rules for relation: u should use same fkname as pkname.
**Rules for db design: do not use "_" in field name.
Ask if u have ny doubt