Symfony2 - Get an entity instead of PersistentCollection in twig
doctrine-orm, php, symfony
Solution
It's because you are trying to access a collection of entities directly. You have to loop your comments collection :
{% for comment in post.comments %}
// You can get your comment entity here
// for example
<p>{{comment.description}}</p>
{% endfor %}
Problem
I'm using symfony2, and I can't manage to get my related entity in twig. So I have my main entity, let's call it Post, which has a OneToMany relation : ``` /** * @ORM\OneToMany(targetEntity="Comment", mappedBy="Post", cascade={"persist", "remove"}) */ private $comments; ``` And I'm passing it to twig with my controller, I can access every property, but when I try to access a property with relations like "Comment", i'm getting a "Doctrine\ORM\PersistentCollection)" which has a lot of private property, and I can't manage to get the properties of this related entity... I'm a little confused, and I don't know what I'm doing wrong...