I am getting the following error in my "Create Product" page when trying to create a foreign key mapping (i.e mapping Category to Product):
A "__toString()" method was not found on the objects of type "CJ\BusinessBundle\Entity\Category" passed to the choice field. To read a custom getter instead, set the option "property" to the desired property path.
You need to add a __toString()
method to your Category entity. For example:
public function __toString()
{
return $this->name;
}
The PHP magic-method __toString()
is used to present a textual representation of the object. In this case, the Category name will be used when selecting a Category in a Form of a related entity.
The error message is telling you what you need to do. In your Category entity you need to add a __toString() method so that when you add a product it knows what to name each item in the select box on the form.
public function __toString()
{
return $this->name;
}
In the above replace 'name' with whichever field is the readable identifier for your category.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With