保存与 Doctrine 2 的 OneToMany 和 ManyToMany 关系时出错
我对“Doctrine2”有疑问。当尝试保存关系“ManyToMany”或“OneToOne”时,PHP 会留下异常错误!我留下错误以便您可以帮助我。
致命错误:未捕获的异常“InvalidArgumentException”,消息为“通过关系”实体\用户#特权“发现了一个新实体”,该实体未配置为级联持久操作实体:实体\特权@ 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();
在实体用户中我有这个:
/** @OneToOne(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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将cascade={"persist"} 添加到您的权限字段:
Add cascade={"persist"} to your privilege field:
执行以下操作之一:
1- 对用户和电子邮件对象使用持久性
或
2- 将级联添加到您的实体
Do one of these:
1- use persist for both user and email objects
or
2- add cascade to your entity