【发布时间】:2012-02-20 17:04:17
【问题描述】:
我有一个用户表,想使用用户名(这是一个电子邮件地址)作为 id 字段,所以我使用生成的:'assigned" 映射来执行此操作。我还添加了用户名字段的约束被验证为电子邮件地址,但这不是强制的。这是我的用户类:
class User {
transient springSecurityService
String username
String password
String firstName
String lastName
static hasMany = [accounts: Account]
static hasOne = [company:Company]
static belongsTo = Company
static constraints = {
username blank: false, unique: true, email: true
password blank: false
accounts nullable:true
}
static mapping = {
password column: '`password`'
id generator:'assigned', name:'username', property:'username'
}
基本上,我试图将用户的电子邮件用作 id 字段,并将其用作与其他对象的关系中的外键(作为用户与 Account 的一对多关系),但是当我尝试在 dbconsole 中手动添加用户名,它可以让我添加任何字符串。
如何强制执行电子邮件限制?
【问题讨论】: