I have an entity with a manyToOne relation on the same entity
class Post {
/**
* @ORM\OneToMany(targetEntity=Post::class, mappedBy="lotParent")
*/
private $linkedPosts;
}
How can I serialize all my posts properties for the main post without serializing all the properties of the children ?
my yaml serialisation file is like this but all the propoerties are visible for the children :
App\Entity\Post:
ExclusionPolicy: ALL
properties:
id:
expose: true
groups: [viewPost, viewChildPost]
title:
expose: true
groups: [viewPost]
......
linkedPosts:
expose: true
groups: [viewChildPost]
I don't want the children title in this example.
Can I use symfony expressions on serialization groups ? I didn't saw something like this
My Answer:
parentPost")_ */_ private $childPosts;_ /**_ * @ORM\ManyToOne(targetEntity=Post::class, inversedBy="childPosts")_ */_ private $parentPost;_}I want to serialize this entity using JMS Serializer in Symfony. How can I achieve this?
Rate this post
5 of 5 based on 2310 votesComments