Show All "has_Many" Related Data In Cgridview

Let’s say I have a model called User, who has many Pages and these Pages have many Comments.

On a user view with an $id as a parameter I want to load that user with all his pages and all the comments from all these pages.




public actionMyAction($id) {


    $criteria = new CDbCriteria();

    $criteria->condition = "t.id = $id";

    $criteria->with = array('pages', 'pages.comments);


    $model = User::model()->find($criteria); //or    $model = User::model()->findAll($criteria); 


}



$model has everything I need. If I use find() it returns an object, if I use findAll() it returns an array. In any case, it will return only 1 user as the IDs are unique.

Now, the only thing I can get is 1 row in the CGridView with the name of the user.

How can I show something like this:

User 1 | Page 1 | Comment 1


User 1 | Page 1 | Comment 2


User 1 | Page 1 | Comment 3


User 1 | Page 2 | Comment 1


User 1 | Page 2 | Comment 2


User 1 | Page 3 | Comment 1

Thanks

Why don’t you use “Comment” as the main model?




public actionMyAction($id) {


    $criteria = new CDbCriteria();

    $criteria->with = array('pages', 'pages.user');

    $criteria->condition = "user.id = $id";


    $models = Comment::model()->findAll($criteria);

}



Ok. Looks like I get what I want but it crashes because that table has more than 150k rows. Do I have to use CActiveDataProvider for pagination or something like this?

EDIT:

Done.




$dataProvider=new CActiveDataProvider($model, array(

    'criteria'=>$criteria,

    'pagination'=>array(

    'pageSize'=>10,

    ),

));