Reputation: 605
I have an entity representing a user in my system and each user is linked to a comments entity (one-to-many), I have added the comments entity lately and now I noticed that when I update the user entity and the user has comments I get an error, while the user still doesn't have comments everything works fine. I need the related entity only for get the count of comments, I've tried few ways but nothing seems to work.
[2014-12-08 23:31:19] request.CRITICAL: Uncaught PHP Exception Symfony\Component\Form\Exception\StringCastException: "A "__toString()" method was not found on the objects of type "FFS2013\CommentBundle\Entity\Comment" passed to the choice field. To read a custom getter instead, set the option "property" to the desired property path." at /Users/matan/www/FFS2013/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php line 432 {"exception":"[object] (Symfony\Component\Form\Exception\StringCastException: A \"__toString()\" method was not found on the objects of type \"FFS2013\CommentBundle\Entity\Comment\" passed to the choice field. To read a custom getter instead, set the option \"property\" to the desired property path.
I understand that it says he tried to look for the __toString method but I'm don't think this is my real problem. This is the way the relation is configured on the user entity:
@ORM\OneToMany(targetEntity="FFS2013\CommentBundle\Entity\Comment", mappedBy="user", fetch="EXTRA_LAZY")
How can I configured a count property on the user entity and that it will be ignored when updating the entity?
Upvotes: 0
Views: 159
Reputation: 422
You have added Comments relation as choice field in form, so You should implement method __toString in Comment class to display comments in choice field (object is casted to string, so it must have method __toString). Or set property option (in form builder) with another field used to display in choice widget.
Upvotes: 2