2

We want to search for the translated name in Shopware 6 programatically and came up with this:

$criteria = (new Criteria())
   ->addAssociation('property_group_option_translation.name')
   ->addFilter(new EqualsFilter('name', $value))
   ->addFilter(new EqualsFilter('id', $propertyGroupId));

return $this->propertyGroupOptionRepository->search($criteria, Context::createDefaultContext())->getEntities()->first();

But we get

Shopware\Core\Framework\DataAbstractionLayer\Dbal\Exception\UnmappedFieldException : Field "name" in entity "property_group_option" was not found.

How to search for a translated entity in general and in this specific case?

Roman
  • 2,530
  • 2
  • 27
  • 50
Alex
  • 32,506
  • 16
  • 106
  • 171

1 Answers1

2

EDIT:

This should be working

$criteria = (new Criteria())
    ->addAssociation('property_group_option_translation')
    ->addFilter(new EqualsFilter('property_group_id', $propertyGroupId))
    ->addFilter(new EqualsFilter('name', $value));

Wrong old answer

This is not working:

$criteria = (new Criteria())
    ->addFilter(new EqualsFilter('property_group_id', $propertyGroupId))
    ->getAssociation('property_group_option_translation')
       ->addFilter(new EqualsFilter('name', $value));

See also

https://stackoverflow.com/a/67649705/288568

Alex
  • 32,506
  • 16
  • 106
  • 171