【发布时间】:2015-11-12 07:48:46
【问题描述】:
我正在尝试使用Doctrine2/QueryBuilder 构建innerJoin 查询。
$repo = $this->getDoctrine()
->getRepository('MyBundle:Models');
$query = $repo->createQueryBuilder('m')
->where('m.id = :id')
->setParameter('id', $id);
教义说:
连接总是属于 from 子句的一部分。这就是为什么你 必须将连接所属的 FROM 部分的别名指定为 第一个参数。
作为第二个和第三个参数,您可以指定名称和别名 连接表和第四个参数包含 ON 子句。
例如
$queryBuilder
->innerJoin('u', 'phonenumbers', 'p', 'u.id = p.user_id');
我无法理解的是'phonenumbers' 表引用了Entity Name 或DB Table Name。
我真正想要的是,有没有办法明确引用实体,如
innerJoin('u', 'MyBundle:phonenumbers', 'p', 'u.id = p.user_id')?
像这样加入的时候有点混乱。谁能给我解释一下?
救命!!
【问题讨论】:
标签: php mysql symfony doctrine-orm