【发布时间】:2012-02-24 05:56:52
【问题描述】:
我有一个像这样的域三域类:
Tasks.groovy
class Tasks {
static belongsTo = [ user : User ]
//other fields
Date startDate
Date endDate
}
User.groovy
class User {
//relationships. . . .
static belongsTo = [ company : Company, role : Role, resource : Resource]
static hasMany = [ holidays : Holiday, tasks : Tasks]
//other fields
}
Holiday.groovy
class Holiday {
static belongsTo = User
Date startDate
Date endDate
//other fields
}
现在,当我创建 Tasks 实例时,我想设置一个约束,使 Tasks startDate 和 endDate 不属于 User 的 Holidays startDate和endDate。如果有,则抛出错误。
我想要一种方法将这个约束放在我的域类本身上(即Tasks)。
可以吗?
提前致谢。
【问题讨论】:
标签: grails groovy constraints grails-domain-class grails-validation