Symfony2 FOSUserBundle邀请:'inversedBy'映射错误

时间:2012-10-31 01:17:28

标签: symfony entity fosuserbundle

FOSUserBundle邀请函的安装已完成,作为手册 从表面上看,它确实有效 但是,分析器会显示映射错误 我认为“反转”的设置是按照手册中的规定设定的 你怎么看?

实体

/** @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;

    // ...

概述

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.

1 个答案:

答案 0 :(得分:0)

根据参考http://docs.doctrine-project.org/en/2.0.x/reference/association-mapping.html,反面(在本例中为Invitation)必须将User称为“mappedBy”,而不是“inversedBy”。试试

class Invitation
{
    /**
     * @ORM\OneToOne(targetEntity="User", mappedBy="invitation", cascade={"persist", "merge"})
     */
    protected $user;

    // ...