0

I have just spotted that even if I select partial with id and name fields, Doctrine automatically adds all foreign keys to selected fields. How to turn it off globally or per query? I saw it when I was looking for an answer like here: Why is DoctrineExtensions Blameable eagerly fetching all created_by users.

My query looks like this:

$queryBuilder = $this->getEntityManager()->createQueryBuilder()
   ->select('partial c.{id, name}')
   ->from('MyBundle:Car', 'c')
   ->where('c.slug = :slug')
   ->setParameter('slug', $slug);

Which generates:

SELECT m0_.id AS id_0, m0_.name AS mname_1 m0_.created_by AS created_by_5, m0_.updated_by AS updated_by_6, m0_.config_id AS config_id_7, m0_.client_id AS client_id_8 
FROM cars m0_ 
WHERE m0_.mslug = ? 
["audi-a8"] []
Tom
  • 1,203
  • 3
  • 15
  • 35
  • Do you have your `createdBy` and `updatedBy` relationships marked with `fetch="EAGER"`? – Wilt Jan 09 '17 at 12:20
  • @Wilt No. I didn't it mark in any way. After I found the issue I have added a link to in my questions I have even set it as EXTRA_LAZY but it didn't help. So the first thing is that createdBy and UpdatedBy behaves like EAGER and other FKs are just added to the query - in both cases I don't know why. – Tom Jan 09 '17 at 12:35

0 Answers0