我正在使用 EasyAdmin 捆绑包。当我尝试在名为“Company”的实体中添加一个与“Service”实体具有“ManyToMany”关系的新元素时,出现错误:
Error: Method AppBundle\Entity\Service::__toString() must not throw an exception
但是当我要在“服务”实体中添加一个新元素时,一切正常,“公司”实体的字段显示正确。
我试图捕获实现此解决方法的异常,但它没有生效。
服务类:
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Company
*
* @ORM\Table(name="company")
* @ORM\Entity(repositoryClass="AppBundle\Repository\CompanyRepository")
*/
class Company
{
/**
* @var
*
* Many Companys have Many Services.
* @ORM\ManyToMany(targetEntity="Service", inversedBy="companys")
* @ORM\JoinTable(name="companys_services")
*/
private $services;
public function __construct() {
$this->services = new ArrayCollection();
}
public function __toString()
{
return $this->name;
}
}
和服务类:
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Service
*
* @ORM\Table(name="service")
* @ORM\Entity(repositoryClass="AppBundle\Repository\ServiceRepository")
*/
class Service
{
/**
* Many Services have Many Companys.
* @ORM\ManyToMany(targetEntity="Company", mappedBy="services")
*/
private $companys;
public function __construct()
{
$this->companys = new ArrayCollection();
}
public function __toString()
{
return (string) $this->name;
}
}
怎么了?