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

标签 symfony doctrine-orm fosuserbundle

我正在将 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/

相关文章:

symfony - Silex + Doctrine2 ORM + 下拉菜单(实体类型)

symfony - AuthenticationSuccessHandler,登录后重定向和referer

ajax - ajax 请求后 Symfony2 登录重定向

symfony - 如何在 FOSUserBundle 中明确禁用注册

mysql - Symfony2 : embedding form with many-to-many entities throws exception

php - Symfony 2 中实体管理器和 phpunit 的问题

php - preload.php 文件在哪里,它是如何生成的?

symfony - 检查当前请求是否安全(ssl)

php - Symfony 3 表单生成器 : block_name not working

php - 无法通过存储库中的标识变量选择实体