Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getArrayResult on entity with ManyToOne association

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:

  1. The actual generated SQL contains the foreign key field to be returned (i.e. ClientID)
  2. 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_  
like image 418
MarkOfSine Avatar asked Mar 30 '11 11:03

MarkOfSine


1 Answers

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);
like image 159
romanb Avatar answered Sep 18 '22 01:09

romanb