Question

I thought the purpose of the query builder object was to help dynamically build queries. However, any time I try to use the query builder in this kind of a context, the helper methods overwrite one another. For example:

$object_identifiers_I_need = array("Obj_One", "Obj_Two", "Obj_Three");
$qb = $em->createQueryBuilder();
foreach($object_identifiers_I_need as $object_identifier){
    $qb->add('select', $object_identifier)
}

returns only:

SELECT Obj_Three ...

rather than the desired

SELECT Obj_One, Obj_Two, Obj_Three ...

Am I missing something? Is there a way to add multiple selects without sticking them all in an array in a single call?

Was it helpful?

Solution

From doctrine documentation: All helper methods in QueryBuilder actually rely on a single one: add(). This method is responsible of building every piece of DQL. It takes 3 parameters: $dqlPartName, $dqlPart and $append (default=false).

After changing the default behavior of $append to true, this is working much better for me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top