在dql(学说)中两列的基础上连接两个表


Joining two tables on the basis of Two colums in dql(Doctrine)

*我想在两列的基础上联接表。

  • 我有一个类似这样的dql联接查询-

    $qb=$this->em->createQueryBuilder();
    $from = 'Entities'User u';
    $qb->select('u.id User_Id, u.name User_Name, evtvst.event Event_id,evt.name   eventname, cty.name City,ctry.name Country')
    ->add('from', $from)
    ->join('Entities'EventVisitor','evtvst','with','u.id=evtvst.user')
    ->join('Entities'Event','evt','with','evt.id=evtvst.event')...........#
    ->join('Entities'Country','ctry','with','evt.country=ctry.id')
    ->join('Entities'City','cty','with','evt.city=cty.id')
    ->where('evtvst.user=?1')
    ->setParameter(1,$_GET["user"])
    ->setFirstResult($i)
    ->setMaxResults($max_result)
    ->distinct();
    $query = $qb->getQuery();
    $query->getSQl();
    $results = $query->getResult();
    

现在我要添加一个条件到#标记的列像这样-

->join("实体''事件"、"vt"、"with"、"vt.id=evtvst.Event"answers"evt.eventEdition=evtvst.edition")

但它不起作用。请告诉我怎么做。

好了,现在我找到了这个的解决方案

您只需要在第二次应用联接时更改表的别名。我已经这样做了

    ->join('Entities'EventVisitor','evtvst','with','u.id=evtvst.user')
    ->join('Entities'Event','evt','with','evt.id=evtvst.event')
    ->join('Entities'Event','evt1','with','evt1.eventEdition=evtvst.edition')
    ->join('Entities'Country','ctry','with','evt.country=ctry.id')
    ->join('Entities'City','cty','with','evt.city=cty.id')
    ->where('evtvst.user=?1') 

而且运行良好。