0
votes

I have a situation that I need a related field from the relation field.

I have 3 Entity:

  1. Media Object (imageUrl needed)
  2. Author (image)
  3. Comment (author)

So when I call /api/comment/1 I want to se imageUrl from the author.

I tried to add @Groups({"author_object:read", "author"}) on media entity, and also on image of the author, but no luck... Any tips?

1

1 Answers

0
votes
  1. Add a group "comment_object:read to normalizationContext in @ApiResource of Comment or to 'normalization_context' of the operations you want to show the imageUrl,
  2. Add an annotation @Groups({"comment_object:read"}) to Comment::$author property or if you already have one, add the group name to it
  3. Add the same group annotation to Author::$image or if you already have one, add the group name to it
  4. Add the same group annotation to MediaObject::imageUrl or if you already have one, add the group name to it

You can use a different name for the group as long as you use the same name in all the above annotations

The chapter4-api branch of my tutorial describes something similar for Employee and Hours registration, a working example is in chapter5-api.