我有一个像这样的域三域类:
任务.groovy
class Tasks {
static belongsTo = [ user : User ]
//other fields
Date startDate
Date endDate
}
用户.groovy
class User {
//relationships. . . .
static belongsTo = [ company : Company, role : Role, resource : Resource]
static hasMany = [ holidays : Holiday, tasks : Tasks]
//other fields
}
假日.groovy
class Holiday {
static belongsTo = User
Date startDate
Date endDate
//other fields
}
现在,当我创建一个Tasks
实例时,我想设置一个约束,使Tasks
startDate
andendDate
不属于User
' Holiday
sstartDate
和endDate
。如果有,则抛出和错误。
我想要一种方法来将此约束放在我的域类本身上(即 on Tasks
)。
有可能这样做吗?
提前致谢。