I’ve a association in my EntityDefinition:
...
class ParentEntityDefinition extends EntityDefinition
{
...
protected function defineFields(): FieldCollection
{
return new FieldCollection([
(new OneToOneAssociationField(
'childEntity',
'id',
'parent_entity_id',
ChildEntityDefinition::class,
false)),
]);
}
...
}
The ChildEntity
has a fk_field to currency_entity. To avoid an additional request to get the currency, my question:
- Is, and if, how is it posible to get the currency entity with nested association?
2
Answers
Yes that is totally possible.
You can add nested associations in the following way:
Note the dot syntax to specify nested associations, the same syntax can be used over the HTTP-API as well.
Take a look at the official docs as well: https://developer.shopware.com/docs/guides/plugins/plugins/framework/data-handling/reading-data#associations
Yes, just use the dot notation to chain associations when you create the
Criteria
programmatically. Given you use the repository of the parent entity:In the request body for an API search request: