【问题标题】:Doctrine - extracting a column from a tableDoctrine - 从表中提取列
【发布时间】:2011-12-02 18:11:45
【问题描述】:

当我做这样的事情时:

$boards = Doctrine_Query::create()
                        ->select('bds.id')
                        ->from('board bds')
                        ->whereIn('bds.type', $boardtype)
                        ->orderBy('bds.id')
                        ->execute();

结果 $boards 的字段(列)比我想要的要多。我想要的只是一个表板列 ID 的单个数组。有没有办法做到这一点?

我想在类似下面的地方使用数组:

$buildings = Doctrine_Core::getTable('building')->createQuery('a')
                                                ->WhereIn('a.board_id', $boards)
                                                ->orderBy('a.id')
                                                ->execute();

但是 WhereIn 只需要一个数组而不是一个查询,所以现在我必须遍历 $boards 并为 WhereIn 生成一个 ID 数组。

因此,我想知道是否可以将列检索为数组?或者如果我正在做的事情有其他选择。感谢您的帮助。

背景信息:
Board 与 Building 具有多对一的关系。 Board 的 ID(键)列与 Building 中的 board_id 列相关。
我想要实现的是生成与给定板类型的板相关联的建筑物的查询。

【问题讨论】:

    标签: mysql doctrine symfony1


    【解决方案1】:

    您应该阅读:http://www.doctrine-project.org/documentation/manual/1_2/en/data-hydrators

    $boards = Doctrine_Query::create()
                        ->select('bds.id')
                        ->from('board bds')
                        ->whereIn('bds.type', $boardtype)
                        ->orderBy('bds.id')
                        ->execute(array(), Doctrine_Core::HYDRATE_SINGLE_SCALAR);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多