Symfony2 FOSUserBundle Invitation : 'inversedBy' mapping errors

流过昼夜 提交于 2020-01-16 04:47:07

问题


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?

Entity

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

回答1:


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;

    // ...


来源:https://stackoverflow.com/questions/13149930/symfony2-fosuserbundle-invitation-inversedby-mapping-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!