0

I'm following Sulu example here: https://github.com/sulu/sulu-workshop/ trying to set translations for custom entity type.

My entity file has getter for field "home_team" defined like:

/**
 * @Serializer\VirtualProperty(name="home_team")
 */
public function getHomeTeam(): ?string
{
    $translation = $this->getTranslation($this->locale);
    if (!$translation) {
        return null;
    }
    return $translation->getHomeTeam();
}

So field is not actually part of that entity, but of it's translation entity since it suppose to be translatable.

When I try to create new object of that entity type it works well. I can see in database that field values are stored well and I don't get any error.

But on overview page instead of list of all objects I get error:

[Semantical Error] line 0, col 73 near 'home_team AS': Error: Class App\Entity\MatchEvent has no field or association named home_team

Any idea what could be wrong here?

MilanG
  • 6,994
  • 2
  • 35
  • 64

1 Answers1

0

If you wanna see the translation in the listView you have to create a real translationEntity, like in the workshop project. In this post it is already explained, how to translate a custom entity correctly.

If you have already created your translationEntity you have to configure the relation of the translation to your main entity via a join. Here is an example in the workshop for this configuration.

Sulu uses optimised queries to create the list-object directly from the database. So the entity itself does not get hydrated or serialised for performance reasons. Thus your virtualProperty is never executed.

Prokyon
  • 128
  • 7