我認爲你需要更多地考慮到您的domainClasses嘗試的意見/控制器前:
你有一個域對象(在我的情況專輯對象)不同的域(車)
域類:
class User {
String name
static hasMany = [orders:Orders]
}
Class Album {
String name
}
class Order {
User user
Album album
}
查看:控制器行動,顯示此:
<!-- by defining user.id and album.id when grails receives the .id it binds that id to the actual object so --!>
<!-- User user = params.user // is the user object bound to user.id --!>
<g:form action="save" controller="myController">
<g:hidden name="user.id" value="1"/>
<g:select name="album.id" from="${mypackage.Album.list()}" optionKey="id" optionValue="name"/>
<g:submitButton name="save">
</g:form>
控制器來接收拯救行動 - 節能功能應該被接管的事務服務=這只是對你來說非常基本顯示:
package mypackage
class MyController {
def save() {
Order order= new Order(params)
order.save()
//
//User user=User.get(params.user.id)
User user=params.user
user.addToOrders(order)
user.save()
render "album added to order class and then order added to users class"
}
}