【问题标题】:Doctrine query returns extra field in result教义查询在结果中返回额外字段
【发布时间】:2011-05-17 15:03:00
【问题描述】:

我有一个教义查询;

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

【问题讨论】:

    标签: mysql doctrine doctrine-1.2


    【解决方案1】:

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

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

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

    【讨论】:

    • 这很有意义。谢谢 Jweible。
    • @Sid 很高兴我能帮上忙。不久前我不得不自己解决同样的问题。
    • 通过返回多个值的查询,我怎样才能得到一个只有值的一维数组?
    猜你喜欢
    • 2011-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-09
    • 1970-01-01
    相关资源
    最近更新 更多