Doctrine查询返回结果中的额外字段 [英] Doctrine query returns extra field in result
问题描述
我有一个Doctrine查询;
I have a Doctrine query;
$q = Doctrine_Query::create()->select('s.monthly_volume')
->from('SearchVolume s')
->innerJoin('s.Keywords k')
->where('k.group_id = ?',array($group_id));
我只是希望它返回结果数组中的monthly_volume值。它目前返回monthly_volume和id,我不希望它返回结果中的id。
I just want it to return the monthly_volume value in the result array. It currently returns monthly_volume and id, I don't want it to return the id in result.
推荐答案
Doctrine自动添加主在几乎每种类型的水合模式下,结果的关键字段。
Doctrine automatically adds the primary key field to the results in almost every type of hydration mode.
在这种情况下,您想要一个简单的数组,只有一个字段被选中,答案是单标量水化模式。使用它像这样:
In a case like this where you want a simple array and only have a single field being selected, the answer is the Single Scalar Hydration mode. Use it like this:
$q = Doctrine_Query::create()->select('s.monthly_volume')
->from('SearchVolume s')
->innerJoin('s.Keywords k')
->where('k.group_id = ?');
$monthly_volumes = $q->execute(array($group_id), Doctrine_Core::HYDRATE_SINGLE_SCALAR);
你应该会发现$ monthly_volumes是一个简单的一维数组,只包含你的值想要。
You should find that $monthly_volumes is a simple one-dimensional array containing only the value(s) you wanted.
这篇关于Doctrine查询返回结果中的额外字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!