【发布时间】:2018-01-06 18:13:25
【问题描述】:
我将 Doctrine 和 ResultSetMappingBuilder 与 addMetaResult() 一起使用。
我在我的存储库中获得了本地查询,并映射到实体,它运行良好,代码结构如下:
$rsm = new ResultSetMappingBuilder($entityManager);
$rsm->addRootEntityFromClassMetadata('AppBundle\Entity\Example', 'e');
$rsm->addFieldResult('e', 'id', 'id');
$rsm->addMetaResult('e', 'value', 'value');
$sql = "SELECT id, 5 as value FROM table";
$query = $entityManager->createNativeQuery($sql, $rsm)
$result = $query->getResult();
我的 entity.yml 看起来像这样:
AppBundle\Entity\Example:
...
fields:
id:
type: smallint
nullable: false
options:
unsigned: true
id: true
generator:
strategy: IDENTITY
value:
type: integer
但是当我在其他地方使用标准实体管理器方法时,像这样:
$this->exampleRepo->find(5);
然后我得到错误:
找不到列:1054“字段列表”中的未知列“t0.value”
这是因为我的表中没有真正的列“值”,它是元列。如果该列不在 Native Query 中,是否有任何配置跳过该列,或者如果它不存在则跳过,或者我必须覆盖存储库中的方法 find() 并在其中添加映射?
【问题讨论】:
标签: php symfony doctrine-orm