与Doctrine 2保存OneToMany和ManyToMany关系的错误 [英] error saving OneToMany and ManyToMany relationship with Doctrine 2
问题描述
致命错误:未捕获的异常'InvalidArgumentException'与消息'一个新的实体通过关系实体找到通过\用户#privilege'未配置为级联持久化实体的操作:实体\权限@ 0000000012feb12000000000616126d4。明确地或坚持新的实体设置级联持续关系的操作。如果您无法通过实现实体Entities \ Privilege#__toString()来找出哪些原因导致问题,以获得线索。 C:\ Program Files \ EasyPHP-5.3.4.0 \ www \ mframework_2 \ phpinc \ Doctrine \ ORM \ UnitOfWork.php第576行
我用于保持关系的代码是:
$ user = new \Entities\User );
$ user-> setActive(true);
$ user-> setUsername('xxx');
$ user-> setPassword('xxx');
$ email = new \Entities\Email();
$ email-> setEmail(xxx');
$ email-> setType('xxx');
$ user-> addEmail($ email);
$ this-> em-> persist($ user);
$ this-> em-> flush();
在Entitie用户中我有:
/ ** @OneToOne(targetEntity =Privilege)* /
protected $ privilege;
我有同样的问题whit ManyToMany关系!
非常感谢!
将cascade = {persist}添加到您的特权字段中:
/ ** @OneToOne(cascade = {persist},targetEntity =Privilege)* /
protected $ privilege;
I have a problem with "Doctrine2". When attempting to save a relationship "ManyToMany" or "OneToOne" PHP leave exception error! I leave the error so that you can help me.
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'A new entity WAS found Through the Relationship' Entities \ User # privilege 'That Was not configured to cascade persist Operations for entity: Entities \ Privilege @ 0000000012feb12000000000616126d4. Explicitly or persist the new entity set up cascading persist Operations on the relationship. If you can not find out Which Causes the problem by implementing entity 'Entities \ Privilege # __toString ()' to get a clue. "in C: \ Program Files \ EasyPHP-5.3.4.0 \ www \ mframework_2 \ phpinc \ Doctrine \ ORM \ UnitOfWork.php on line 576
The code I use to keep the relationship is:
$user = new \Entities\User(); $user->setActive(true); $user->setUsername('xxx'); $user->setPassword('xxx'); $email = new \Entities\Email(); $email->setEmail(xxx'); $email->setType('xxx'); $user->addEmail($email); $this->em->persist($user); $this->em->flush();
In the Entitie User I have this:
/** @OneToOne(targetEntity="Privilege") */ protected $privilege;
I have the same problem whit ManyToMany relationships!
Thankyou very much!
Add cascade={"persist"} to your privilege field:
/** @OneToOne(cascade={"persist"}, targetEntity="Privilege") */
protected $privilege;
这篇关于与Doctrine 2保存OneToMany和ManyToMany关系的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!