通过带有本地查询的Doctrine ResultSetMapping获取标量关联数组

时间:2019-05-27 08:52:36

标签: symfony doctrine doctrine-native-query

因此,我想使用ResultSetMapping获取已经准备好的数据数组。现在我只得到field => value例。我如何获得

'alias' => [
    'field1' => 'value1',
    'field2' => 'value2',
],
...
How I retrieve now:

    $rsm = new ResultSetMappingBuilder($this->em);
    $rsm->addScalarResult('uuid', 'uuid');
    $rsm->addScalarResult('date', 'date');

    // here need to provide somehow common index "employee"
    $rsm->addScalarResult('employeeUuid', 'employeeUuid');
    $rsm->addScalarResult('employeeFullName', 'employeeFullName');

    // here need to provide somehow common index "pathwayPatient"
    $rsm->addScalarResult('pathwayPatientUuid', 'pathwayPatientUuid');
    $rsm->addScalarResult('pathwayPatientTitle', 'pathwayPatientTitle');

所以我期望下一个结构:

$result = [
    'uuid' => $row['uuid'],
    'date' => $row['date'],
    'pathwayPatient' => [
        'uuid' => $row['pathwayPatientUuid'],
        'title' => $row['pathwayPatientTitle']
    ],
    'employee' => [
        'uuid' => $row['employeeUuid'],
        'fullName' => $row['employeeFullName']
    ]
];

关于如何以这种方式获取内容的任何想法?当然,除了写foreach并满足我的所有需求:)

0 个答案:

没有答案