現在のユーザーがコメントしたすべての投稿を取得する方法。テーブル間に関係がありますが、状況は私には難しいです。次のようになります。
$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);
これです。