Skip to content

EntityFilterType fails to filter with related entities with UUID or ULID identifiers #208

@maxmishyn

Description

@maxmishyn

When we have entity where id is defined using one of Symfony\Component\Uid..... types, EntityFilterType is able to generate list, to render active fileter applied, but it faild to add filtering parameter correctly to the queryBuilder.

Example:

use Symfony\Component\Uid\Ulid;
class Product 
{
    #[ORM\Id]
    #[ORM\Column(type: UlidType::NAME, unique: true)]
    private Ulid $id;
    public function getId(): Ulid
    {
         return $this->id;
    }
}

class Batch
{
    #[ORM\ManyToOne]
    #[ORM\JoinColumn(nullable: false)]
    private ?Product $product = null;
}

We apply filter as usual:

            $builder
                ->addFilter('product', EntityFilterType::class, [
                    'form_options' => [
                        'class' => Product::class,
                        'choice_label' => 'name',
                    ],
                    'choice_label' => 'name',
                ]);

As a result doctrine tries to execure something like:
SELECT count(*) AS sclr_0 FROM batch b0_ WHERE (b0_.product_id = '01JR5KAQXPAS26X4W9WPEV9407') AND (b0_.deleted_at IS NULL);
and fails to find anything as product_id is binary and not string.

So far I was able to narrow it down to the create method in Kreyu\Bundle\DataTableBundle\Bridge\Doctrine\Orm\Filter\ParameterFactory class.

It creates parameters with Doctrine\ORM\Query\Parameter(), but ony 2 parameters being passed to the constructor. The third one is one of doctrine's binding types. Without if constructor calls ParameterTypeInferer::inferType($value) to determine the type, bus since it is object, it simply falls back to the string value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions