开发者

symfony doctrine pagination brings more data than set per page

I am setting 1 row per page in symfony pager but its showing more data than 1. It is because my query is left joining the sfGuardUser table with other tables and it is causing duplication of 'sfGuardUser' row in some cases when there are multiple entries in 'license' table for that particular user ! Here is my query:

    $pager = new sfDoctrinePager('sfGuardUser', '1');

     $q = Doctrine_Query::create()
                        ->select('u.id, u.username, g.name, l.id, l.status,             l.client_id, l.vendor_id, l.applied_date, p.org_name')
                        ->from('sfGuardUser u')
                        ->leftJoin('u.Profile p')
                        ->leftJoin('u.Groups g')
                        ->leftJoin('u.LicensedClients l')
                        ->where('g.name = \'vendor\'')
                        ->orderBy('l.applied_date');

     $q->setHydrationMode(Doctrine_Core::HYDRATE_SCALAR);

     $pager->setQuery($q);
     $pager->setPage($request->getParameter('page', 1));
     $pager->init();

The pagination is there, but problem is in some cases there are multiple rows shown in one page when there are multiple rows for a particular user in the license table. How can I implement it in a right 开发者_如何学运维way ?


What do you want to achieve with joining user and license table (1:n relation) when paging through (sfGuard)Users ?

If you want to sort users by license type/date/count, you could use

DISTINCT u.id, u.username
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜