Grails 动态 "inList"
Grails dynamic "inList"
这几乎与这个老问题相同: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.
我知道,"correct" 处理这个问题的方法是使 someValue
成为 SomeOtherDomain
的一个实例,而不是仅仅存储名称,但这不太合适。我们希望能够在不破坏所属域的保存值的情况下删除 SomeOtherDomain
的实例...具有已删除值的域将无效,并且必须在保存前更新,但是 archived/locked 记录仍然存在并可以显示。
您可以像这样为筛选窗格指定值列表:
<filterpane:filterPane domain="MyObject" filterPropertyValues="${['someValue':[values: SomeOtherDomain.list().collect{it.name}]]}" />
然后只需使用自定义验证器进行实际验证。我不确定什么脚手架可能会使用 inList,但如果您愿意用静态页面替换一些脚手架页面,那么很容易解决这个问题。
这几乎与这个老问题相同: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.
我知道,"correct" 处理这个问题的方法是使 someValue
成为 SomeOtherDomain
的一个实例,而不是仅仅存储名称,但这不太合适。我们希望能够在不破坏所属域的保存值的情况下删除 SomeOtherDomain
的实例...具有已删除值的域将无效,并且必须在保存前更新,但是 archived/locked 记录仍然存在并可以显示。
您可以像这样为筛选窗格指定值列表:
<filterpane:filterPane domain="MyObject" filterPropertyValues="${['someValue':[values: SomeOtherDomain.list().collect{it.name}]]}" />
然后只需使用自定义验证器进行实际验证。我不确定什么脚手架可能会使用 inList,但如果您愿意用静态页面替换一些脚手架页面,那么很容易解决这个问题。