我想获取一些实体,以避免大量额外的查询,我也想获得相关集合的数量。
这样的事情:
SELECT u, a, count(p) properties_count
FROM User u
JOIN u.address a
LEFT JOIN u.properties p
group by u.id
那就是我希望获得像[[0 => User, 'properties_count' => 42], [0 => ...], ...]
这样的集合。
没有抓取加入(SELECT u, count(p) properties_count
),但SELECT u, a, count(p) properties_count
似乎不包括计数
结果。
我做错了吗?
答案 0 :(得分:0)
看起来这只是原始查询中的一个错误。
它正在使用这样的连接:
LEFT JOIN Address a WITH a.id = u.address
当我将其替换为
时LEFT JOIN u.address a
它开始工作了。 (我认为它们是等价的)