Php Symfony:带内部联接的分页
我需要实现分页。看起来,该学说并不支持某些联合 我的问题是:Php Symfony:带内部联接的分页,php,symfony,doctrine-orm,pagination,Php,Symfony,Doctrine Orm,Pagination,我需要实现分页。看起来,该学说并不支持某些联合 我的问题是: $query = $this->getEntityManager() ->createQueryBuilder(); $query->setFirstResult(($page - 1) * $maxperpage); $query->setMaxResults($maxperpage); $query->select('d') ->from('Deman
$query = $this->getEntityManager()
->createQueryBuilder();
$query->setFirstResult(($page - 1) * $maxperpage);
$query->setMaxResults($maxperpage);
$query->select('d')
->from('DemandeBundle:Declaration', 'd')
->orderBy('d.id', 'ASC')
->innerJoin('ContactBundle:Contact', 'c', 'WITH', 'd.contact = c')
->where('c.structure_id = :structure_id')
->setParameter('structure_id', $structureId)
->getQuery()
->getResult();
return new Paginator($query, true);
当我不使用innerJoin时,它工作正常,但我需要使用它,以便只显示与我的用户有关的请求
使用innerJoin时,我遇到了这样的错误:
"An exception has been thrown during the rendering of a template
("Cannot count query which selects two FROM components, cannot make distinction") in
DemandeBundle:Demande:listing_demande.html.twig at line 25"
我如何避免这个问题而不使用另一个包或任何东西
希望你能理解我,伙计。你的
声明
与联系人
有什么关系吗
您最好在联系人
中有指向声明的多通
关系。这样,它将起作用,因为您将没有两个来自组件,而是一个来自组件
然后,修改查询以执行以下操作:
->innerJoin('d.contant', 'c')
完整查询应如下所示:
$query->select('d')
->from('DemandeBundle:Declaration', 'd')
->orderBy('d.id', 'ASC')
->innerJoin('d.contact', 'c') // <-- THIS LINE IS CRITICAL
->where('c.structure_id = :structure_id')
->setParameter('structure_id', $structureId)
->getQuery()
->getResult();
$query->select('d')
->from('DemandeBundle:Declaration','d')
->订购人('d.id','ASC')
->innerJoin('d.contact','c')//其中('c.structure\u id=:structure\u id'))
->setParameter('structure_id',$structureId)
->getQuery()
->getResult();
最后,我找到了一个解决方案:
而不是:
$query->select('d')
->from('DemandeBundle:Declaration', 'd')
->orderBy('d.id', 'ASC')
->innerJoin('ContactBundle:Contact', 'c', 'WITH', 'd.contact = c')
->where('c.structure_id = :structure_id')
->setParameter('structure_id', $structureId)
->getQuery()
->getResult();
我用过:
$query->select('d')
->add('from', 'SgaDemandeBundle:Declaration d INNER JOIN d.contact c')
->where('c.structure_id = :structure_id')
->setParameter('structure_id', $structureId)
->orderBy('d.id', 'ASC')
->getQuery();
Yes声明与联系人相关,具体方式为:@ORM\manytone(targetEntity=“Sga\ContactBundle\Entity\Contact”,inversedBy=“declarations”,cascade={“persist”,“merge”})*@ORM\JoinColumns({*@ORM\JoinColumn(name=“Contact\u id”,referencedColumnName=“id”)*})。然后就是用我写的一行替换innerJoin
行。我已经用你的行替换了我的行,但它不起作用。它不识别c。正常情况下,它不知道哪个类与c.$query->select('d')->from('SgaDemandeBundle:Declaration','d')->innerJoin('d.contact=c')->where('c.structure_id=:structure_id')->setParameter('structure_id',$structureId)->orderBy('d.id',ASC')->getQuery()->getResult();我得到了“[Syntax Error]第0行,第68列:错误:字符串的预期结尾,得到了'c'”,这不是innerJoin('d.contact=c')
,而是innerJoin('d.contact','c')
。我已经编辑了答案,包括完整的QueryBuilder
construction。。。