Php 使用部分对象语法的别名字段+;第2条规则中的数组
在原则2中使用时,是否有任何方法来别名字段 我知道我能做到:Php 使用部分对象语法的别名字段+;第2条规则中的数组,php,orm,doctrine-orm,doctrine,Php,Orm,Doctrine Orm,Doctrine,在原则2中使用时,是否有任何方法来别名字段 我知道我能做到: $this->createQueryBuilder('user')->select([ 'user.id AS id', 'user.firstName AS first_name', 'user.lastName AS last_name', 'user.email AS email', 'user.dateCreated AS date_created' ])->
$this->createQueryBuilder('user')->select([
'user.id AS id',
'user.firstName AS first_name',
'user.lastName AS last_name',
'user.email AS email',
'user.dateCreated AS date_created'
])->getQuery()->getArrayResult();
但是,我需要使用部分对象语法,以便条令在嵌套关系继承权中检索结果:
$this->createQueryBuilder('team')
->select('PARTIAL team.{id, name, dateCreated}, s, PARTIAL e.{id, name}')
->innerJoin('team.session', 's')
->innerJoin('s.event', 'e')
->getQuery()->getArrayResult();
我在Doctrine\ORM\Internal\Hydration\ArrayHydrator
中搜索,但没有看到任何挂钩或任何东西,而且看起来Doctrine没有postSelect
事件或允许我实现自己的变异的东西
谢谢你的帮助 效率不是很高,但最后我自己修改了密钥
希望有更好的方法,如果没有,我希望这对某人有所帮助。问题不仅在于别名,还在于括号。基本上,它非常差,不允许使用别名或括号。它期望出现昏迷或列表末尾,其他所有内容都会抛出语法错误 我想使用这样的SUM()函数检索部分对象集合
public function findByCompetition(array $competition)
{
$competitionField = $competition['field'] ?? 'Id';
$competitionValue = $competition['value'] ?? 0;
$teamsCompStatsByComp = $this->createQueryBuilder('t')
->select('partial t.{Id, competitionId, competitionOldId, teamId, teamOldId, SUM(goalsAttempted) goalsAttempted}')
->where('t.'.$competitionField.' = ?1')
->groupBy('t.teamId')
->orderBy('t.Id', 'ASC')
->setParameter('1', $competitionValue)
->getQuery()
->getResult()
;
return new ArrayCollection($teamsCompStatsByComp);
}
但得到了相同的错误
[语法错误]第0行,第85列:错误:预期的条令\ORM\Query\Lexer::T_CLOSE\u CURLY_BRACE,get'('
我必须以数组的形式检索数据,在外键上使用IDENTITY(),然后手动添加实体
public function findByCompetition(array $competition)
{
$competitionField = $competition['field'] ?? 'Id';
$competitionValue = $competition['value'] ?? 0;
$teamsCompStatsByComp = $this->createQueryBuilder('t')
->select('t.Id, IDENTITY(t.competitionId) competitionId, t.competitionOldId, IDENTITY(t.teamId) teamId, t.teamOldId, SUM(goalsAttempted) goalsAttempted')
->where('t.'.$competitionField.' = ?1')
->groupBy('t.teamId')
->orderBy('t.Id', 'ASC')
->setParameter('1', $competitionValue)
->getQuery()
->getResult()
;
foreach ($teamsCompStatsByComp as $key => $teamCompStats) {
$teamsCompStatsByComp[$key] = new TeamStatistics($teamCompStats);
}
return new ArrayCollection($teamsCompStatsByComp);
}
我认为我们应该开始讨论如何改进部分语法行为