I'm trying to create a filter of AdminUser that created an entry on our blog, but when I search something, it shows me an error:
An exception has been thrown during the rendering of a template ("[Semantical Error] line 0, col 67 near 'author.username': Error: 'author' is not defined.") in SyliusAdminBundle:Crud:_grid.html.twig at line 30.
The table shows perfectly:
fields:
author:
type: twig
label: dinamic.ui.author
options:
template: DinamicSyliusBlogBundle:Post/Field:author.html.twig
I looked at the Grid of orders to know how search about customers, and i copied it from there. But nothing.
filters:
author:
type: string
label: dinamic.ui.author
options:
fields: [author.username, author.email]
Hooking to the Doctrine queries, i found one difference. On my query, doctrine isn't creating a LEFT JOIN relation to get data of my Grid.
SELECT count(DISTINCT s0_.id) AS sclr0 FROM sylius_order s0_ LEFT JOIN sylius_customer s1_ ON s0_.customer_id = s1_.id WHERE s0_.completed_at IS NOT NULL AND (s1_.email LIKE '%Osv%' OR s1_.first_name LIKE '%Osv%' OR s1_.last_name LIKE '%Osv%')
Post grid filtering by author (AdminUser)
SELECT o FROM App\Bundle\SyliusBlogBundle\Entity\Post o WHERE (author.username LIKE '%Osv%' OR author.email LIKE '%Osv%') AND o.published = :published ORDER BY o.createdAt desc
Orders grid uses custom repository method https://github.com/Sylius/Sylius/blob/master/src/Sylius/Bundle/AdminBundle/Resources/config/grids/order.yml#L9 - there's join you're looking for https://github.com/Sylius/Sylius/blob/master/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/OrderRepository.php#L32
Yeah, thanks a lot @Raptek I didn't see that 馃憤
Works perfectly!
Most helpful comment
Orders grid uses custom repository method https://github.com/Sylius/Sylius/blob/master/src/Sylius/Bundle/AdminBundle/Resources/config/grids/order.yml#L9 - there's join you're looking for https://github.com/Sylius/Sylius/blob/master/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/OrderRepository.php#L32