While experimenting with MANY_MANY and CGRIDVIEW, I came across to a strange one. Here is my scenario:
There are 2 Models: Games and Developers (Many-to-Many Relation)
While listing games and their developers in a gridview I use the following :
public function search()
{
$criteria=new CDbCriteria;
$criteria->with = array(‘developers’);
$criteria->together = true;
return new CActiveDataProvider(‘Game’, array(
‘criteria’=>$criteria,
‘sort’=>array(‘defaultOrder’=>‘t.name ASC’,),
‘pagination’=>array(
‘pageSize’=> 5,),));
}
If there are 5 games, each having one developer, there is no problem.
If there are 5 games, first one having 2 developers, and others have one developer, only the first 4 games are listed.
I checked the forums but couldn’t find an answer except this post which may seem related to this problem.
Same happens when I try a Has_Many relation.
Also, when I add
$criteria->group = ‘t.gameid’
to my criteria, the paging problem disappears, but when I try to get games.developers, there is only the first developer from the MANY_MANY relation. Since I need all the results this is not a solution.
Thanks for your help.
Edit: When I omit $criteria->together = true; the problem again disappears, however I need it to filter the gridview by developer.name