Having the follow basic tables (one-to-many relationship)
Client - Has many users.
Users - Each user belongs to single client.
In a very simple example if I query the user entity (Querybuilder)
with getArrayResult()
I see the following:
- The actual generated SQL contains the foreign key field to be returned (i.e. ClientID)
- The actual returned data array does NOT contain the foreign key field.
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?
Query is:
$qb = $this->_em->createQueryBuilder();
$qb->select('e');
$qb->from('Entity\User', 'e');
SQL is:
SELECT w0_.Id AS Id0, w0_.Name AS Name2, w0_.ClientID AS ClientID7
FROM users w0_
Try to set the
HINT_INCLUDE_META_COLUMNS
query hint on the query (not the builder) before you execute it.As far as I know, you can't do this, because ClientID is not a property of User. User has a property like $client, and that client entity has an $id.
This is confusing you because you're dealing with Entites but you're still thinking in SQL.
The solution, though slightly less efficient, would probably be to join the Client entity into your DQL query, and then get
$results[N]['client']['id']
(or similar, I'm not too familiar with getResultArray())