Sylius/SyliusGridBundle

Broken String filter when filtering over multiple relations

Opened this issue · 0 comments

Description
Grid string filter doesn't work properly when filtering by multiple relations. The expression builder joins foreign relations using an INNER JOIN – if any relation is missing, nothing will be returned. The filter would work correctly if LEFT JOIN was used.

Steps to reproduce
Filter by multiple fields, eg. in the order admin of the Sylius framework:

      filters:
        customer:
          type: string
          label: sylius.ui.customer
          options: {fields: [customer.user.email, customer.defaultAddress.company]}

Generated SQL query (pseudo code):

SELECT * FROM sylius_customer c
INNER JOIN sylius_shop_user u ON c.id = u.customer_id
INNER JOIN sylius_address a ON a.id = c.default_address_id
WHERE (u.email LIKE '%value%' OR a.company LIKE '%value%')
  • Filtering by existing customer e-mail won't work if the customer has no default address.
  • Filtering by valid company name won't work if the customer has no user

Possible Solution
Use LEFT JOINs, let WHERE statements do their job.