So I've gotten a decent system for User/Profile Relations with Has_One and Belongs_To. But I was wondering what the best way to go about this would be? I'm not sure if I should declare the relation in both the models or not and if so, Which one?
So I've gotten a decent system for User/Profile Relations with Has_One and Belongs_To. But I was wondering what the best way to go about this would be? I'm not sure if I should declare the relation in both the models or not and if so, Which one?
User
id
userProfileId
…
UserProfile
id
…
imho:
'profile' => array(self::BELONGS_TO, 'UserProfile', 'userProfileId')
It depends on whether you will access those relations.
Quote
Well I'll have to pull the username on the profile pages and I'll need to have a profile/user management system for the user of course.
Just so I'm sure, Here's what I'm doing right now.
User Model
'profile'=>array(self::HAS_ONE, 'Profile', 'userId'),
Profile Model
'user'=>array(self::BELONGS_TO, 'User', 'userId'),
Profile Show View
<td><?php $user=$profile->user; echo CHtml::encode($user->username); ?>
User Show View
<?php $profile=$user->profile; echo $profile->id ?>
Anything wrong with that system?
You are doing fine. You can use CHtml::encode($profile->user->username) directly, though.
Quote
Great to hear. And thanks for that tip. I’m going to be posting large bits of the basic code for people to learn from. Once I learn it myself of course.