Doctrine won't let me select specific fields

拥有回忆 提交于 2019-11-29 03:57:46
Ярослав Рахматуллин

From the documentation on "Partial Object Syntax":

By default when you run a DQL query in Doctrine and select only a subset of the fields for a given entity, you do not receive objects back. Instead, you receive only arrays as a flat rectangular result set, similar to how you would if you were just using SQL directly and joining some data.

If you want to select partial objects you can use the partial DQL keyword.

php console doctrine:query:dql --hydrate array \
   'SELECT partial s.{name ,id}, partial c.{name, id } 
    FROM DatabaseBundle:ProductCategories c 
    JOIN c.suppliers s ORDER BY s.name, c.name'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!