代码之家  ›  专栏  ›  技术社区  ›  Michael Emerson

当不需要参数时,在原则中使用连接语句

  •  0
  • Michael Emerson  · 技术社区  · 9 年前

    我已经了解了连接语法在Doctrine站点上的工作方式(仅以下示例):

    $qb->join('u.Group', 'g', 'WITH', 'u.status = ?1', 'g.id')
    

    但我不想匹配特定的值,我只想以我在mySQL中的方式加入它,如下所示:

    ...JOIN table2 ON table2.id = table1.existingCustomer
    

    这是我当前的搜索DQL,其中 m 表示一个名为消息和的表 c 表示名为Customer的表:

    $qb = $this->createQueryBuilder('m');
    $qb->select('m');
    $qb->where('c.firstName LIKE :s');
    $qb->orWhere('c.surname LIKE :s');
    $qb->orWhere('m.postcode LIKE :s');
    $qb->orWhere('m.town LIKE :s');
    $qb->orWhere('m.phone1 LIKE :s');
    $qb->andWhere('m.archived = :archived');
    $qb->orderBy('m.messageDate', 'DESC')
        ->setParameter('s', '%'.$s.'%')
        ->setParameter('archived', 0);
    return $qb->getQuery()->getResult();
    

    正如你所看到的,这里提到了 c

    我需要知道的是,有没有一种方法可以通过链接 existingCustomer id 客户表的字段,而不必匹配特定的值以使其工作?

    1 回复  |  直到 9 年前
        1
  •  1
  •   cn007b Dheerendra Kulkarni    9 年前

    你试过这个吗:

    us \Doctrine\ORM\Query\Expr\Join;
    // ...
    ->leftJoin('YourBundle:Table2', 'table2', Join::WITH, 'table2.id = table1.existingCustomer')