Skip to content

Multiple JOINS to same table and filters fails at ORM/ExpressionBuilder #314

@enpepet

Description

@enpepet

The problem is that when using a Filter it adds the condition to the first join if there are multiple joins with same table.

at src/Bundle/Doctrine/ORM/ExpressionBuilder.php resolveFieldByAddingJoins calls getFieldDetails that returns the name of relation and field without alias, then it search for this new name at JOINS and find allways the first one, this is wrong.

Example of select with two joins to same table
SELECT App\Entity\Product o LEFT JOIN o.productTaxons tree1 LEFT JOIN o.productTaxons tree2

Then when using a filter (Sylius\Component\Grid\Filtering\FilterInterface)

public function apply(DataSourceInterface $dataSource, string $name, $data, array $options): void { $eb = $dataSource->getExpressionBuilder(); $dataSource->restrict($eb->in('tree2.taxon', $data['product_type'])); }

But the condition goes to tree1 !! The first one.

In my case i solved it using standard Doctrine Expr, and not using grid ExpressionBuilder.

But this happens also when ordering.

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