Reputation: 5679
I have a tree structure, it is managed by Gedmo\Tree
. I want to make complex update for one field in subtree, this update requires join with another table, it is not supported by DQL. So I want to get DQL builder by Gedmo\Tree
repository method childrenQueryBuilder
, convert it to QueryBuilder
and add update statement.
$dqlQueryBuilder = $repository->childrenQueryBuilder($node, ...);
$dqlQueryBuilder->resetDQLParts(['select', 'orderBy']);
$queryBuilder = convert($dqlQueryBuilder);
$queryBuilder->leftJoin('...', 'lj');
$queryBuilder->update('node.update', 'concat(node.field, lj.field)');
I know that I can write custom QueryBuilder
, I just wonder if such conversions are possible by doctrine builtin tools or some 3-rd party libraries.
Upvotes: 0
Views: 1379
Reputation: 10910
There's no such thing as SQLQueryBuilder in Doctrine, there's only QueryBuilder
which is an DQL Query Builder. What you can do is to convert DQL
to SQL
by doing
$stringSql = $queryBuilder->getQuery()
->getSQL();
Once you have it you might play with native sql and then execute it as a raw sql.
Note: I'm not sure what exact DB Specific statement you mean, but there's a possibility to map DB Specific functions to DQL by making use of FunctionNode
class. Once you have your function mapped to DQL you might accomplish it with DQL only.
Check documentation on how to work with custom DB functions in DQL
Upvotes: 1