一对一关系的映射无效

时间:2016-05-10 19:41:34

标签: doctrine-orm doctrine symfony-2.8

我试图在两个Entities之间创建一个One-to-one bidirectional mapping,但我得到的是这个错误:

# app/console doctrine:schema:validate --env=dev_local

[Mapping]  FAIL - The entity-class 'Belka\AuthBundle\Entity\Globaltoken' mapping is invalid:
* The association Belka\AuthBundle\Entity\Globaltoken#user refers to the inverse side field Belka\AuthBundle\Entity\User#globaltoken which does not exist.

[Mapping]  FAIL - The entity-class 'Belka\AuthBundle\Entity\User' mapping is invalid:
* The mappings Belka\AuthBundle\Entity\User#globalToken and Belka\AuthBundle\Entity\Globaltoken#user are inconsistent with each other.

这些是我的实体:

用户实体

/**
 * @ORM\Entity
 * @ORM\Table(name="app_auth.""User""", schema="app_auth")
 * @ORM\Entity(repositoryClass="UserRepository")
 * @UniqueEntity("username", groups={"strict"})
 * @UniqueEntity("email", groups={"strict"})
 * @Assert\GroupSequence({"User", "strict"})
 */
class User implements EncoderAwareInterface
{
    /**
     * @ORM\Id
     * @ORM\Column(type="string")
     * @Assert\NotBlank(message = "user.username.not_blank")
     * @ORM\GeneratedValue(strategy="NONE")
     * @Serializer\Groups({"default"})
     */
    private $username;

    /**
     * @ORM\Id
     * @ORM\Column(type="string")
     * @Assert\NotBlank(message = "user.email.not_blank")
     * @Assert\Email(message = "user.email.not_valid")
     * @Serializer\Groups({"default"})
     */
    private $email;

    /**
     * @ORM\Column(type="string", nullable=true)
     * @Serializer\Groups("personal")
     */
    private $password;

    /**
     * @ORM\Column(type="string")
     * @Serializer\Groups({"default"})
     */
    private $name;

    /**
     * @ORM\Column(type="string")
     * @Serializer\Groups({"default"})
     */
    private $surname;

    /**
     * @ORM\Column(type="string", length=5)
     * @Serializer\Groups({"default"})
     */
    private $lang;

    /**
     * @ORM\Column(type="boolean")
     * @Serializer\Groups({"strict_adm"})
     */
    private $deleted = false;

    /**
     * @ORM\OneToOne(targetEntity="Globaltoken", mappedBy="user", cascade={"persist"})
     * @Serializer\Groups({"strict"})
     */
    private $globalToken;

    <removed methods>
    }

Globaltoken实体

/**
 * @ORM\Entity
 * @ORM\Table(name="app_auth.""Globaltoken""", schema="app_auth")
 * @ORM\Entity(repositoryClass="GlobaltokenRepository")
 * @UniqueEntity("token", groups={"strict"})
 * @UniqueEntity("last_use", groups={"strict"})
 * @Assert\GroupSequence({"Globaltoken", "default", "strict"})
 * @ORM\HasLifecycleCallbacks()
 */
class Globaltoken
{
    //10 minutes, expressed in seconds
    const VALIDITYINTERVAL = 600;

    /**
     * @ORM\Id
     * @ORM\Column(type="string")
     * @ORM\GeneratedValue(strategy="NONE")
     * @Serializer\Groups({"strict"})
     */
    private $token;

    /**
     * @ORM\OneToOne(targetEntity="User", inversedBy="globaltoken")
     * @ORM\JoinColumns({
     *       @ORM\JoinColumn(name="owned_by_username", referencedColumnName="username"),
     *       @ORM\JoinColumn(name="owned_by_email", referencedColumnName="email")
     * })
     * @Serializer\Groups({"strict"})
     */
    private $user;

    /**
     * @ORM\Column(type="datetime")
     * @Assert\NotBlank()
     * @Serializer\Groups({"strict"})
     */
    private $last_use;

    /**
     * @Serializer\Groups({"default"})
     */
    private $expiring;

    <removed methods>
    }

你认为它可能是什么?

1 个答案:

答案 0 :(得分:0)

知道了。大写错字是所有事情的责任:

User::globalToken inversedBy="globaltoken"期望的内容。 User::globaltoken是。

我陷入了IT开发中最经典的陷阱之一,我说这会让自己分心。我对PHPStorm对Symfony注释的支持感到非常失望。