0
从阅读文档和另一个stackoverflow后,我认为如果我只想返回几列数据,正确的方法在教条是使用部分。 (这是一个只读查询)。Symfony2 Doctrine2使用部分
但是,下面的代码返回所有100列,而不是我确定的3。有人能解释为什么吗?
感谢, MANISHA
public function showAction(Request $request)
{
if ($request->getMethod() == 'GET') {
$id = $request->get('locationid');
$kfType = $request->get('type');
$em = $this->getDoctrine()
->getManager();
$data = $em->createQueryBuilder()
->select (array('partial d.{id, locationid, kfFyp}'))
->from('DashDataBundle:Data', 'd')
->where('d.locationid = :locationid')
->setParameter('locationid', $id)
->setMaxResults(100)
->getQuery()
->getResult();
}
谢谢!这使它像我希望的那样工作,只显示了我在返回的数组中要求的字段而不是整个对象。 – manisha
因为我没有使用整个对象,我应该用QueryBuilder吗?最好只使用DQL? – manisha
没有太大的区别。可能纯粹的dql快一点。它只是建立查询,没有别的 –