一对一关系的无效映射

Invalid mapping for a one-to-one relation

我正在尝试在两个 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>
    }

你认为它可能是什么?

知道了。大写错字是一切的罪魁祸首:

User::globalToken 不是 inversedBy="globaltoken" 所期望的。 User::globaltoken是。

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