如何获取当前用户发表评论的所有帖子。我有表之间的关系,但情况对我来说很难。它应该是这样的:
$posts = Yii::app()->user->comments->posts->findAll(); // don't think that is my code, it just for explanation of query chain
所以我需要获取用户发表评论的所有帖子。
在 sql 中,我的查询工作正常:
SELECT tc.title, tc.content, t.post_id
FROM tbl_comment t
JOIN tbl_post tc
ON t.post_id =tc.id
WHERE author_id =43
GROUP BY t.post_id
$CD = new CDbCriteria;
$CD->condition = 'tc.author_id='.Yii::app()->user->id;
$CD->join = 'JOIN tbl_comment tc ON t.id=tc.post_id';
$posts = Post::model()->findAll($CD);
就是这个。