Best way to paginate related data?

I don't think it's really possible to do it in one sql query.

<?php


	public function actionShow() {


		$id = isset($_GET['id']) ? $_GET['id'] : Yii::app()->user->id;


			


		$criteria=new CDbCriteria;


		$pages=new CPagination(Post::model()->count($criteria)); //this will return the wrong result as it actually depends on the JOIN used which is not defined until later


		$pages->pageSize=4;


		$pages->applyLimit($criteria);


		


		$user = User::model()->with('post', 'post.parsecache', 'parsecache')->together()->findbyPk($id, $criteria);


		


		if (!$user)


			throw new CHttpException(404,'The requested user does not exist.');


			


		$this->render('show', compact('user', 'pages'));


	}


When you do counting, you should also use those "with". Otherwise your count won't be correct in this case.

That wasn't working either.  I'm just going to to 2 queries with the following, i'm tired of this debugging:

<?php


	public function actionShow() {


		$user = $this->loadUser(isset($_GET['id']) ? $_GET['id'] : Yii::app()->user->id);


			


		$criteria=new CDbCriteria;


		$criteria->condition = '`post`.`user_id`=''.$user->id.''';


		$pages=new CPagination(Post::model()->count($criteria));


		$pages->pageSize=4;


		$pages->applyLimit($criteria);


		$user->post = Post::model()->with('parsecache')->together()->findAll($criteria);


			


		$this->render('show', compact('user', 'pages'));


	}