0

I have some scenario like below :

/**
 * @ORM\Entity
 * @ORM\Table(name="role")
 */
class Role
{
    /**
     * @ORM\OneToMany(targetEntity="RolesFeatures", mappedBy="role", cascade={"all"})
     **/
    private $rolesFeatures;
}

In my index file I would like to get them:

{{ role.rolesFeatures.getId() }}

I get this :

 An exception has been thrown during the rendering of a template ("Catchable Fatal
 Error: Object of class Doctrine\ORM\PersistentCollection could not be converted to string
 in C:\wamp\www\PMI_sf2\app\cache\dev\twig\63\81\679fca1c2da64d0ebbcd5661bc6d.php line 99")
 in PMIHomePagesBundle:HomePages:mainHome.html.twig at line 49.

How I can Cast Doctrine\ORM\PersistentCollection to it real object class ?

pmoubed
  • 3,842
  • 10
  • 37
  • 60

1 Answers1

4

rolesFeatures is an array so you need to iterate over it. Something like:

{% for roleFeature in role.rolesFeatures %}
    {{ roleFeature.id }}
{% endfor %}
Cerad
  • 48,157
  • 8
  • 90
  • 92
  • I get this error : Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken::serialize() must return a string or NULL – pmoubed May 24 '12 at 20:30
  • @PMoubed Does it matched for you? because I have a similar problem [here](http://stackoverflow.com/questions/28175708/query-a-manytomany-relation-and-display-the-good-result-in-symfony-with-doctrine). Thank you to help if you can. –  Jan 28 '15 at 15:57