Skip to content

QueryBuilder: Query hints not remembered on getQuery() (Returns a fresh object every time). Add hint option to QueryBuilder. #11849

Open
@Jalliuz

Description

@Jalliuz

Feature Request

What

It would be nice if we could set query hints on the QueryBuilder so they are added to the new Query object when you do ->getQuery()

Why

I have some utility classes for optimising the query, for example:

  • function addDistinctWhenToMany(QueryBuilder $qb): Check if we have a toMany join, if so add "$qb->distinct" and $qb->getQuery()->setHint(Query\SqlWalker::HINT_DISTINCT, true)

The reason for doing this is because blindly adding "distinct" to the query lowers performance so I only want to add it if its needed.
But if later in the process you do getQuery() again, all the previously set hints are gone because it creates a "new Query()" every time

The above is just an example, I have other use cases to set an output_walker hint if necessary and so on.

How

Adding an array to the QueryBuilder "customHints" or something like that.
And every time ->getQuery gets executed, the customHints from QueryBuilder are taken into account and added automatically

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions