本文介绍了Symfony2 FOSUserBundle邀请:“ inversedBy”映射错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
FOSUserBundle邀请的安装已按照手册完成。
从表面上看,它确实可以工作。
但是,探查器会显示映射错误。
我认为已按照手册中的说明设置了 inversedBy。
您怎么看?
FOSUserBundle Invitation's installation was completed as the manual.
On the surface, it does work.
However, mapping errors is displayed by profiler.
I think that a setting of 'inversedBy' was set as prescribed in the manual.
How do you see it?
实体
/** @ORM\Entity */
class Invitation
{
/**
* @ORM\OneToOne(targetEntity="User", inversedBy="invitation", cascade={"persist", "merge"})
*/
protected $user;
// ...
/**
* @ORM\Entity
* @ORM\Table(name="fos_user")
*/
class User extends \FOS\UserBundle\Entity\User
{
/**
* @ORM\OneToOne(targetEntity="Invitation", inversedBy="user")
* @ORM\JoinColumn(referencedColumnName="code")
* @Assert\NotNull(message="Your invitation is wrong")
*/
protected $invitation;
// ...
Profiler
FOS\UserBundle\Entity\User Valid
My\SampleBundle\Entity\User
The field My\SampleBundle\Entity\User#invitation is on the owning side of a bi-directional
relationship, but the specified mappedBy association
on the target-entity My\SampleBundle\Entity\Invitation# does not contain
the required 'inversedBy' attribute.
My\SampleBundle\Entity\Invitation
The field My\SampleBundle\Entity\Invitation#user is on the owning side of a bi-directional
relationship, but the specified mappedBy association
on the target-entity My\SampleBundle\Entity\User# does not contain
the required 'inversedBy' attribute.
推荐答案
根据参考的反面(在本例中为邀请)必须将用户称为 mappedBy,而不是 inversedBy。尝试
According to reference http://docs.doctrine-project.org/en/2.0.x/reference/association-mapping.html the inverse side (in this case Invitation) must refer to User as "mappedBy", not "inversedBy". Try
class Invitation
{
/**
* @ORM\OneToOne(targetEntity="User", mappedBy="invitation", cascade={"persist", "merge"})
*/
protected $user;
// ...
这篇关于Symfony2 FOSUserBundle邀请:“ inversedBy”映射错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!