即时通讯使用grails 2.4.4。我是新来的,所以我可能有一个菜鸟问题
我有这样的 Realm 类:
class E_PreguntaFrecuente {
static embedded=['perfiles','secciones','subsecciones']
String pregunta
String respuesta
Integer orden
static hasMany=[perfiles:E_Perfil,secciones:E_Seccion,subsecciones:E_Subseccion]
static constraints = {
pregunta blank:false
respuesta blank:false
orden blank:false
subsecciones nullable: true
}
}
我希望子级别的hasMany列表可为空...我该怎么做?我已经尝试了您在代码中看到的内容; subsecciones nullable:true 以及其他一些变体,例如放置(nullable:true),但它们似乎都不起作用,它一直说需要subsecciones列表。
编辑
我没有错误,只想有一个不需要的列表...
这是我的意思的图片,我不知道保存时是否可以为null。但是我什至无法通过表单部分。
最佳答案
因此找到了一种解决方法,或者说多数民众赞成在它的完成方式上,idk,即时消息是新的...
这是_form.gsp文件中生成的标记:
<g:select name="subsecciones" from="${com.test.jwm.E_Subseccion.list()}" multiple="multiple" optionKey="id" size="5" required="" value="${e_PreguntaFrecuenteInstance?.subsecciones*.id}" class="many-to-many"/>
通过删除 required =“” 属性,它可以按预期工作...
我只是不知道如何配置域类,所以它会以这种方式生成...对于其他字符串变量,它仅与 nullable:true Realm 域类中的一起使用...但是,至少我找到了一种解决方法。 。
如果有人知道更好的方法,请分享
关于grails - 可为空的Grails hasMany列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32336949/