-
Notifications
You must be signed in to change notification settings - Fork 120
apply_filter: manipulating QueryBuilder directly vs. returning a Condition? #240
Comments
Hi :), since I've added the 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
if ($values['value'] == 'true') {
return $filterQuery->createCondition('e.relatedEntities is not empty');
}
elseif ($values['value'] == 'false') {
return $filterQuery->createCondition('e.relatedEntities is empty');
}
return null;
}, |
@cedric-g cool, this makes my life easier, thanks. But for the record: Is it bad practice to manipulate the QueryBuilder directly? Why? What's the difference, if any? |
Manipulate directly? That actually is the idea of the library right, or how do you see this as a bad practice? You can also pass it as callable / callback if I'm right. |
It depends on the way you work with the bundle. The fact is, if you choose to add some expressions directly to the doctrine query builder in the |
@cedric-g so now if I have a filter, which has no corresponding field/property, but uses a Repository-method to add a complex
And in the repository to be complete:
This works, but I still have a feeling, that this direct manipulation could have side effects. What are the the downsides of "But these expressions won't be handled by the |
Hi,
I have to filter for the existence of related entities. An elegant way to do this is using the
is empty
expression of DQL. Since I don't know a way to useis empty
withinExpr
contexts, my working code for now is:This works, but I have a strong feeling, that manipulating the QueryBuilder directly is bad practice and I should find a way to express this using
Expr
-constructs instead.So any opnions on this?
Or an idea how I can solve this with the Expressions-interface?
Greets,
spackmat
The text was updated successfully, but these errors were encountered: