модель Post:
Код: Выделить всё
public function relations()
{
return array(
'author' => array(self::BELONGS_TO, 'User', 'author_id'),
'comments'=>array(self::HAS_MANY, 'Comment', 'post_id'),
);
}
Код: Выделить всё
public function relations()
{
return array(
'post'=>array(self::BELONGS_TO, 'Post', 'post_id'),
'author'=>array(self::BELONGS_TO, 'User', 'author_id'),
);
}
Код: Выделить всё
public function relations()
{
return array(
'post' => array(self::HAS_MANY, 'Post', 'author_id'),
'comments'=>array(self::HAS_MANY, 'Comment', 'author_id'),
'profile' => array(self::BELONGS_TO, 'Profile', 'id'),
);
}
Код: Выделить всё
public function relations()
{
return array(
'user' => array(self::BELONGS_TO, 'User', 'user_id'),
);
}
Начинаю с выборки поста
Код: Выделить всё
$criteria->with = array('author'); //пробую писать comments.author.profile не работает, и без with тоже
$post=Post::model()->findByPk($_GET['id'], $criteria);
Код: Выделить всё
foreach($post->comments as $comment) :
$comment->author->username //как и нужно, имя пользователя выводит
$comment->author->profile->avatar //не работает такая конструкция