我有一个使用Doctrine(和PHP Symfony框架)的查询-数组结果:
$qb = $this->createQueryBuilder('t1', 't1.id')
->select('t1')
->where(...)
->getResults()
// Return :
158 => [
"id" => 158
"name" => "Test 1"
]
157 => [
"id" => 157
"name" => "Test 2"
]
我想加入一个表:
$qb->leftJoin(..., 't2', 'WITH', 't2 = ...');
我成功了两种情况(lastPost
表中没有t1
字段; 我只想加入并获取字段):
$qb->addSelect('t2.id AS t0.lastPost')
// Return :
158 => [
0 => [
"id" => 158
"name" => "Test 1"
],
"lastPost" => 161
]
157 => [
0 => [
"id" => 157
"name" => "Test 2"
],
"lastPost" => 163
]
和:
$qb->addSelect('t2 AS t0.lastPost')
// Return :
158 => [
0 => [
"id" => 158
"name" => "Test 1"
]
]
159 => [
"lastPost" => [
"id" => 161,
"name" => "Test 3"
]
]
157 => [
0 => [
"id" => 157
"name" => "Test 2"
]
]
160 => [
"lastPost" => [
"id" => 163,
"name" => "Test 4"
]
]
但是我无法将lastPost添加到原始数组中,例如:
158 => [
0 => [
"id" => 158
"name" => "Test 1"
],
"lastPost" => [
"id" => 161,
"name" => "Test 3"
]
]
157 => [
0 => [
"id" => 157
"name" => "Test 2"
],
"lastPost" => [
"id" => 163,
"name" => "Test 4"
]
]
您能帮我意识到吗? 对不起,我的英语不好,我是法语:)