Skip to content
This repository has been archived by the owner on Feb 4, 2023. It is now read-only.

Problem with dql, filter and global search #972

Open
veolys-nanne opened this issue Sep 28, 2021 · 0 comments
Open

Problem with dql, filter and global search #972

veolys-nanne opened this issue Sep 28, 2021 · 0 comments

Comments

@veolys-nanne
Copy link

veolys-nanne commented Sep 28, 2021

I have entities with binded comments. A comment can be important depending on a flag.
So, I write a custom dql to get a column indicating if the entity contains at last one important comment (could be a BooleanColumn):

$this->columnBuilder
    ->add('has_important_comment', Column::class, array(
        'title' => 'Has important comment',
        'dql' => '(SELECT (CASE WHEN COUNT({c}) > 0 THEN 1 ELSE 0 END) FROM MyBundle:Comment {c} WHERE {c}.entity = entity AND {c}.important = true)',
        'searchable' => true,
    ));

I add a select filter on this column:

$this->columnBuilder
    ->add('has_important_comment', Column::class, array(
        'title' => 'Has important comment',
        'dql' => '(SELECT (CASE WHEN COUNT({c}) > 0 THEN 1 ELSE 0 END) FROM MyBundle:Comment {c} WHERE {c}.entity = entity AND {c}.important = true)',
        'searchable' => true,
        'filter' => [
            SelectFilter::class,
            [
                'search_type' => 'eq',
                'select_options' => ['' => 'Any', '1' => 'Yes', '0' => 'No'],
            ],
        ],
    ));              

It works as expected. I can filter all entities with at last one important comment or all entities with none important comment.
But with global search and filter, both activated, I've got a bug as the dql is used twice in condition.
{c} is replaced by c_search in the LIKE condition for the global search and again by c_search in the eq/Select condition.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant