我有一个 User 实体和一个通过外键链接到 User 的 UserData 实体。
用户实体具有以下映射:
/**
* @ORM\OneToOne(targetEntity="UserData", cascade={"persist", "remove"})
* @var integer
*/
protected $userData;
UserData 有一个简单的 ID 字段:
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
* @var integer
*/
protected $id;
好的; 我想检索一个用户实体,其 UserData 具有字段“NIN”值“A00000000”;我正在尝试使用此 DQL 查询:
SELECT u FROM eCommerceUserBundle:User u JOIN eCommerceUserBundle:UserData ud ON u.userData = ud.id WHERE ud.NIN = :NIN
但我得到这个错误:
预期的 Doctrine\ORM\Query\Lexer::T_WITH,得到 'ON'
所以...我尝试退出 ON 子句,如下所示:
SELECT u FROM eCommerceUserBundle:User u JOIN eCommerceUserBundle:UserData ud WHERE ud.NIN = :NIN
现在的问题是 Doctrine 的原始查询:
SELECT
u0_.id AS id0,
u0_.email AS email1,
u0_.password AS password2,
u0_.created AS created3,
u0_.lastLogin AS lastLogin4,
u0_.confirmed AS confirmed5,
u0_.blocked AS blocked6,
u0_.particularData_id AS particularData_id7,
u0_.institutionalData_id AS institutionalData_id8,
u0_.administratorData_id AS administratorData_id9
FROM
user u0_
INNER JOIN userData u1_ ON (u1_.NIN = ?)
所以看来,Doctrine 正在将我的 WHERE 子句推入 ON 子句......
我能做些什么?