Another similar issue I had is that you can't remove all associated objects with the default scaffolding. Root cause is that if you deselect everything in a select box, nothing from that select box is transferred to the server.
I fixed it by adding a hidden field with empty value for all Collection types. Need to do more testing to see if it has sideeffects.
Here's the changes I did for both the topic I described in the first post and the one described herd:
Code:
diff --git a/content-server-grails/src/templates/scaffolding/create.gsp b/content-server-grails/src/templates/scaffolding/create.gsp
index f638064..2e6dcac 100644
--- a/content-server-grails/src/templates/scaffolding/create.gsp
+++ b/content-server-grails/src/templates/scaffolding/create.gsp
@@ -34,7 +34,7 @@
display = true
boolean hasHibernate = PluginManagerHolder.pluginManager.hasGrailsPlugin('hibernate')
props.each { p ->
- if (!Collection.class.isAssignableFrom(p.type)) {
+ if (!p.isBiDirectional()) {
if (hasHibernate) {
cp = domainClass.constrainedProperties[p.name]
display = (cp ? cp.display : true)
diff --git a/content-server-grails/src/templates/scaffolding/edit.gsp b/content-server-grails/src/templates/scaffolding/edit.gsp
index 41ee197..2c20866 100644
--- a/content-server-grails/src/templates/scaffolding/edit.gsp
+++ b/content-server-grails/src/templates/scaffolding/edit.gsp
@@ -41,7 +41,11 @@
cp = domainClass.constrainedProperties[p.name]
display = (cp?.display ?: true)
}
- if (display) { %>
+
+ if (display) {
+ if (Collection.class.isAssignableFrom(p.type)) {
+ %> <g:hiddenField name="${p.name}" value=""/> <%
+ } %>
<tr class="prop">
<td valign="top" class="name">
If you think it makes sense to get one or both of these changes into the grails scaffolding templates, let me know. I will create the JIRA issues then.