So question is I have Post
and User
models Post
one contains - id, title, body and user_id
fields User
contains - id, name
So what I need is when post is published, it shows user_id
field instead of name
field. I'm struggling this problem please can you help me what I need to do?
First check if you have defined relation in Post model - something like this:
public function relations() {
return array(
'user' => array(self::BELONGS_TO, 'User', 'user_id')
);
}
Now you should get post author (user name) in this way:
$post->user->name;