为什么Doctrine会自动添加外键来查询?

时间:2017-01-08 17:31:30

标签: symfony doctrine-orm doctrine-extensions

我刚刚发现即使我选择带有id和name字段的partial,Doctrine也会自动将所有外键添加到所选字段。如何全局或按查询关闭它?当我在寻找像这样的答案时,我看到了它:Why is DoctrineExtensions Blameable eagerly fetching all created_by users

我的查询如下:

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

生成:

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"] []

0 个答案:

没有答案