Answer the question
In order to leave comments, you need to log in
How to pick up only one entity from the collection when serializing an object using JMSSerializerBundle?
Used by : Symfony 4.1, FOSRestBundle, JMSSerializerBundle
There is an entity Article
that has a one-to-many two-way relationship with ArticleImage
.
class Article
{
private $id;
...
/**
* @ORM\OneToMany(targetEntity="ArticleImage", mappedBy="article")
*/
private $images;
...
}
class ArticleImage
{
private $id;
private $file;
...
/**
* @ORM\ManyToOne(targetEntity="Article", inversedBy="images")
*/
private $article;
private $isPreview;
...
}
ArticleImage
that $isPreview
has a value of true
, and not the entire collection, gets into the result? ArticleImage
items from the collection before serialization, but somehow this option seems to me not the most optimal.
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