将列动态添加到列列表

时间:2012-09-29 21:58:34

标签: php doctrine-orm

我使用查询构建器构建了正确的工作查询。

但是现在有一个条件,一个方法(负责动态地将一些表添加到查询中)必须在查询中添加一列。

我尝试了以下(它更复杂,但几乎相同):

$querybuilder->select('EntityA.Property')
             ->from ('EntityA');

// here is happening some awesome stuff... ;-)
// Now i have to add the Table, and The column

$querybuilder->innerJoin('EntityB'); // this is working
$querybuilder->add('select', 'EntityB.Property'); // overwrites my columnlist
// $querybuilder->select('EntityB.Property'); // also overwrites my columnlist

提前致谢

1 个答案:

答案 0 :(得分:1)

为什么不单独组装select-clause:

$fields = array();

$fields[] = "EntityA.Property"

// code here, and finally, you decide you need EntityB
$fields[] = "EntityB.Property"
$querybuilder->innerJoin('EntityB');

// done with building the query, assign select
$querybuilder->select($fields);