Hi, I have 2 HAS_MANY relation in my blog controller; Images and Comments. When I do an eager loading, I would limit it to 5 image and 10 comments.
I have the following CDbCriteria code in my controller.
$criteria=new CDbCriteria;
$criteria->with=array(
'images'=>array('limit'=>'5'),
'comments'=>array('limit'=>'10'),
);
$criteria->condition="t.id = :id AND t.slug = :slug AND t.status = :status";
$criteria->params = array(
':id' => $id,
':slug' => $slug,
':status' => 1,
);
$model=Post::model()->find($criteria);
I have also tried specifying limit in the relation rules as follow but it doesn’t work as well.
return array(
'images' => array(self::HAS_MANY, 'Image', 'post_id', 'limit'=>'5'),
'comments' => array(self::HAS_MANY, 'Comment', 'post_id', 'limit'=>'10'),
);
It loads all images and comments. Am I missing something out here?