gpt4 book ai didi

symfony - 如何使用 Doctrine Annotations 更改实体子类中的列名称?

转载 作者:行者123 更新时间:2023-12-02 12:02:05 28 4
gpt4 key购买 nike

我正在将 FOSUserBundle 与一个新的 Symfony 项目一起使用,该项目必须使用现有架构。我的用户实体按照说明扩展了 FOS\UserBundle\Entity\User,但电子邮件列被命名为“email_addr”而不是“email”。由于父级定义了 $email 我无法重新声明它来附加我的注释。

 /**
* @var string $emailAddr
*
* @ORM\Column(name="email_addr", type="text", nullable=false)
*/
protected $email;

我得到的异常(exception)是:

[Doctrine\ORM\Mapping\MappingException]                                                                                
Property "email" in "Foo\DataBundle\Entity\User" was already declared, but it must be declared only once

我的问题是:

  • Doctrine2 子类如何使用注释来更改父类中定义的内容?
  • 或者如何覆盖 FOSUserBundle 中的列名称?

最佳答案

我找到了答案:

More about Doctrine implementations

If you need to change the mapping (for instance to adapt the field names to a legacy database), the only solution is to write the whole mapping again without inheriting the mapping from the mapped superclass. In such case, your entity should extend directly from FOS\UserBundle\Model\User (and FOS\UserBundle\Model\Group for the group).

关于symfony - 如何使用 Doctrine Annotations 更改实体子类中的列名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12146929/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com