当前,我正在使用cascadeValidate: 'none'
来避免对关联toOne
的验证,在该关联中,引用域在插入或更新时不应更改。
例如:
class Author {
String name
static constraints = {
name nullable: false, blank: false, unique: true
}
}
class Book {
String title
Author author
static constraints = {
name nullable: false, blank: false
author nullable: false
}
static mapping = {
author cascadeValidate: 'none'
}
}
在这种情况下,无论何时我们插入或更新Book
实例,都不应验证其作者。
BUT,Gorm中有没有办法对toMany
内容执行相同的操作?如果我将以前的代码更新为:
class Author {
String name
List<Book> books
static constraints = {
name nullable: false, blank: false, unique: true
books nullable: false, minSize: 1
}
}
class Book {
String title
Author author
static constraints = {
name nullable: false, blank: false
author nullable: false
}
static mapping = {
author cascadeValidate: 'none'
}
}
为了避免Gorm验证清单中的书籍,我应该定义什么样的映射之王?有办法吗?
我在github上的GORM问题跟踪中获得了帮助,这是有关如何处理这种关联的所有详细信息:https://github.com/grails/grails-data-mapping/issues/1150