如何使用Doctrine注释来更改实体子类中的列名? [英] How can I use Doctrine Annotations to change a column name in an entity subclass?
问题描述
/ **
* @var string $ emailAddr
*
* @ ORM\Column(name =email_addr,type =text,nullable = false)
* /
protected $电子邮件;
我得到的例外是:
[Doctrine\ORM\Mapping\MappingException]
Foo\DataBundle\Entity\User中的属性email已被声明,但必须是只有一次
我的问题是:
- Doctrine2子类如何使用注释来更改父项中定义的内容?
- 或者如何覆盖FOSUserBundle中的列名?
我找到了一个答案:
如果需要更改映射(例如,将字段名称修改为al egacy数据库),唯一的解决方案是再次编写整个映射,而不会继承映射超类的映射。在这种情况下,您的实体应直接从FOS\UserBundle\Model\User(以及该组的FOS\UserBundle\Model\Group)扩展。
I'm using FOSUserBundle with a new Symfony project that has to work with an existing schema. My user entity extends FOS\UserBundle\Entity\User as the instructions say, but the email column is named "email_addr" instead of "email". Since the parent defines $email I can't re-declare it to attach my annotation.
/**
* @var string $emailAddr
*
* @ORM\Column(name="email_addr", type="text", nullable=false)
*/
protected $email;
The exception I get is:
[Doctrine\ORM\Mapping\MappingException]
Property "email" in "Foo\DataBundle\Entity\User" was already declared, but it must be declared only once
My question is either:
- How can a Doctrine2 subclass use an annotation to alter something defined in the parent?
- Or how can I override column names in the FOSUserBundle?
I found an answer:
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).
这篇关于如何使用Doctrine注释来更改实体子类中的列名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!