这几乎与这个老问题相同:
Dynamic define the inList constraint using database query
这一问题基本上没有得到解决,也许在提出这一问题后的几年里取得了进展。
我想填充
inList
域属性的参数,其值来自另一个域。由于自动生成的视图(脚手架、过滤板),这需要来自
inList(内部列表)
而不是自定义验证器。
class MyDomain {
String someValue
static constraints = {
someValue(nullable: true, maxSize: 50, inList: SomeOtherDomain.list()*.name)
}
}
这会在启动时产生以下错误:
Caused by: java.lang.IllegalStateException: Either class [thepackage.SomeOtherDomain] is not a domain class or GORM has not been initialized correctly or has already been shutdown. Ensure GORM is loaded and configured correctly before calling any methods on a GORM entity.
我知道,正确的处理方法是
someValue
的实例
SomeOtherDomain
而不仅仅是存储名称,但这不太合适。我们希望能够删除的实例
SomeOtherDomain其他域
不破坏所属域的保存值。。。具有删除值的域今后将无效,必须在保存前更新,但存档/锁定的记录仍将存在并可以显示。