我在使用自动生成的别名调用子类属性时遇到问题。
这是我使用getSQL()函数打印的查询部分。我可以看到在查询中已经生成了别名。
SELECT r0_.id AS id0, r0_.title AS title1, r0_.created_at AS created_at5, r0_.updated_at AS updated_at6, r1_.date AS date7, r1_.job AS job8, r2_.date AS date13, r2_.time AS time14, r2_.job AS job15
FROM reports r0_
LEFT JOIN reports_small_works r1_ ON r0_.id = r1_.id
LEFT JOIN reports_call_out r2_ ON r0_.id = r2_.id
WHERE r0_.division_id = 1
ORDER BY r0_.id
DESC
如何使用reports_call_out别名?报告是父类和Reports_Call_out& Reports_small_works都是子类,并在Query中附加为LeftJoin默认值。
答案 0 :(得分:1)
我的猜测是,reports_call_out没有" job"列,您正在尝试选择它。你可以使用getDQL()函数发布你的DQL吗?要使用连接表别名,请在连接后传递它,如下所示:
SELECT ...
FROM reports r //r is alias for reports here
LEFT JOIN r.reports_call_out rco ...//rco is alias for reports_call_out here
或者,如果您使用QueryBuilder,请将其传递出去:
/* ReportsRepository.php */
$this->createQueryBuilder('r')//r is alias for reports here
->select('...')
->leftJoin('r.reports_call_out', 'rco')//rco is alias for reports_call_out here