具有 ManyToOne 关联的实体上的 getArrayResult
具有以下基本表(一对多关系)
客户端 - 有很多用户.
用户 - 每个用户属于单个客户端.
Having the follow basic tables (one-to-many relationship)
Client - Has many users.
Users - Each user belongs to single client.
在一个非常简单的例子中,如果我查询用户实体(Querybuilder)使用 getArrayResult()
我看到以下内容:
In a very simple example if I query the user entity (Querybuilder)
with getArrayResult()
I see the following:
- 实际生成的 SQL 中包含了待处理的外键字段返回(即ClientID)
- 实际返回的数据数组不包含外键场地.
现阶段我不需要返回外部数据,所以不需要加入关联的表.
At this stage I do not need to return foreign data and so do not need to join to the associated table.
所以问题是...
我如何或如何返回数组中的外键值?
So question is...
What or how do I return the foreign key value in my array?
查询是:
$qb = $this->_em->createQueryBuilder();
$qb->select('e');
$qb->from('EntityUser', 'e');
SQL 是:
SELECT w0_.Id AS Id0, w0_.Name AS Name2, w0_.ClientID AS ClientID7
FROM users w0_
推荐答案
尝试在执行之前在查询(而不是构建器)上设置 HINT_INCLUDE_META_COLUMNS
查询提示.
Try to set the HINT_INCLUDE_META_COLUMNS
query hint on the query (not the builder) before you execute it.
$q->setHint(Query::HINT_INCLUDE_META_COLUMNS, true);
相关文章