Answer the question
In order to leave comments, you need to log in
How to deal with fields that are indirectly related to the entity?
There is an entity User, he has posts. With each transition to the user's page, we need to return the counted number of his posts. However, the total number of posts is not a field in essence, although it must be returned at once, in a single array, as an object.
As done now, a field is created in the serializer userTotalPosts
, to it access_type: public_method
. In the public method, we do return count($this->getAllPosts()) .
Perhaps there are better approaches?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question