gorm 6.x或7.x中是否有一种方法可以避免验证集合内容?

问题描述 投票:0回答:1

当前,我正在使用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验证清单中的书籍,我应该定义什么样的映射之王?有办法吗?

grails gorm
1个回答
0
投票

我在github上的GORM问题跟踪中获得了帮助,这是有关如何处理这种关联的所有详细信息:https://github.com/grails/grails-data-mapping/issues/1150

© www.soinside.com 2019 - 2024. All rights reserved.