0

我有一个教义查询;

    $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。

4

1 回答 1

1

Doctrine 自动将主键字段添加到几乎每种类型的水合模式的结果中。

在这种情况下,您需要一个简单的数组并且只选择一个字段,答案是 Single Scalar Hydration 模式。像这样使用它:

$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 是一个简单的一维数组,仅包含您想要的值。

于 2011-05-19T01:55:46.690 回答