我在 Zend Framework 2 项目中使用 Doctrine 2 ORM。我试图坚持多对多的关系。我遵循了此处描述的文档(manytomany)。在尝试持久化数据时:$em->persist($form->getData());
我收到了错误:
"The class 'Doctrine\ORM\PersistentCollection' was not found in the chain configured namespaces".
有什么建议么 ?
为了更清楚,我在下面添加了一些代码:
首先,对于多对多关系,我注释了文档中所说的实体:
/**
* @ORM\ManyToMany(targetEntity="\User\Entity\Client", mappedBy="reportSettings")
*/
private $client;
public function __construct() {
$this->client = new ArrayCollection();
}
和
/**
* @ORM\ManyToMany(targetEntity="\Statistics\Entity\ReportSettings", inversedBy="client")
* @ORM\JoinTable(name="report_client_settings",
* joinColumns={@ORM\JoinColumn(name="client_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="report_setting_id", referencedColumnName="id")})
*/
private $reportSettings;
public function __construct() {
$this->reportSettings = new ArrayCollection();
}
并且在控制器中
$form = new UpdateReportSettingsForm();
$form->bind($reportSettings);
$request = new Request();
if ($request->isPost()) {
$form->setData($request->getPost());
if ($form->isValid()) {
$data = $form->getData();
$em->persist($data); // here I got the error - The class 'Doctrine\ORM\PersistentCollection' was not found in the chain configured namespaces
$em->flush();
}
我也以 DoctrineModule\Form\Element\ObjectMultiCheckbox 的形式使用。一个简单的var_dump($data)
- 返回一个持久的集合。