FOSUserBundle:删除 emailCanonical 的唯一索引
我正在尝试删除 emailCanonical 上的唯一索引,以便多个用户可以共享相同的电子邮件地址。但是,我不想直接编辑 FOS/UserBundle/Resources/config/doctrine/User.orm.xml,因为对包本身的任何更新都会删除更改。有什么方法可以覆盖我自己的包中的 emailCanonical 字段,同时扩展基本用户(FOS/UserBundle/Model/User.php)
use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Foo\BarBundle\Constant\SecurityConstant;
class User extends BaseUser {
protected $id;
...
}
提前致谢!
I am trying to remove the unique index on emailCanonical, so that multiple users can share the same email address. However, I do not want to edit FOS/UserBundle/Resources/config/doctrine/User.orm.xml directly as any updates to the bundle itself will remove the change. Is there any way I can override the emailCanonical field in my own bundle, while extending the base user (FOS/UserBundle/Model/User.php)
use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Foo\BarBundle\Constant\SecurityConstant;
class User extends BaseUser {
protected $id;
...
}
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
现在标记的答案(2014 年 10 月 14 日)根本不是正确的答案。
这是唯一正确的解决方案:
您还需要覆盖用户表单的验证组:
我们做了什么?我们只是覆盖验证组以不匹配 FOS 默认验证。相反,您的表单将仅通过
Default
组进行验证。上面描述的验证UniqueEntity
没有任何组将由Default
组匹配。The answer that is marked as right now (14 Oct 2014) is not the right answer at all.
This is the only right solution:
Also you need to override validation groups for your user form:
What did we do? We just overrode validation groups to not match the FOS default validations. Instead your form will be validated only with
Default
group. Described above validationUniqueEntity
that doesn't have any group will be matched byDefault
group.执行此操作的唯一方法是扩展
FOS\UserBundle\Model\User
类,然后重新执行所有映射(User.orm.xml
中的所有内容)你自己。来源:
The only way to do this is to extend the
FOS\UserBundle\Model\User
class and then re-do all of the mapping (everything inUser.orm.xml
) yourself.Sources:
对 Tim 答案的补充,这就是使用 YAML 的方法:
Supplement to Tim's answer, this is how you'd do it using YAML: