【发布时间】:2021-12-18 07:10:33
【问题描述】:
抱歉这个不清楚的问题。
如果没有示例代码,我不知道如何用文字解释我想要什么,所以我第一次在网上找不到解决方案,我就在这里。
我正在使用 Doctrine 进行 Symfony 3.4 项目。
我使用 Doctrine 查询构建器进行以下查询:
$this->em->createQueryBuilder()
->select('p.email', 'pa.value','a.key')
->from('myEntity', 'p')
->join('myOtherEntity', 'pa', Join::WITH, 'pa.myEntity = p.id', )
->join('anOtherOneEntity', 'a', Join::WITH, 'a.id = pa.anOtherOneEntity')
它给了我以下结果:
Array
(
[email] => test@test.com
[value] => 758433
[key] => postalcode
)
Array
(
[email] => test@test.com
[value] => John
[key] => firstname
)
Array
(
[email] => test@test.com
[value] => Doe
[key] => lastname
)
我想->groupBy('email') 得到这个结果:
Array
(
[email] => test@test.com
[postalcode] => 758433
[firstname] => John
[lastname] => Doe
)
我已尝试更新 myEntity 以获取关联值:
private $myAttribute
public function getMyAttribute()
还有我的查询
$this->em->createQueryBuilder()
->select('p.email', 'p.myAttribute')
->from('myEntity', 'p')
但我收到以下错误:
Error: Class AppBundle\Entity\myEntity has no field or association named myAttrib
ute
我认为解决方案是更改我的第一个查询,但我需要一些帮助。
感谢您的宝贵时间。
【问题讨论】:
标签: php sql symfony doctrine symfony-3.4