我有两个域类,Job 和 Description,在一个简单的一对多关系中:
Job.groovy
class Job {
static hasMany = [descriptions: Description]
static mapping = {
descriptions lazy: false
}
}
说明.groovy
class Description {
static belongsTo = [job: Job]
}
我有两个控制器动作:
def removeDescriptionFromJob(Long id) {
def jobInstance = Job.get(id)
System.out.println("before remove: " + jobInstance.descriptions.toString())
def description = jobInstance.descriptions.find { true }
jobInstance.removeFromDescriptions(description)
jobInstance.save(flush: true)
System.out.println("after remove: " + jobInstance.descriptions.toString())
redirect(action: "show", id: id)
}
def show(Long id) {
def jobInstance = Job.get(id)
System.out.println("in show: " + jobInstance.descriptions.toString())
}
这是我提交 removeDescriptionFromJob 请求时打印的内容:
before remove: [myapp.Description : 1]
after remove: []
in show: [myapp.Description : 1]
为什么描述在 removeDescriptionFromJob 操作中被删除,然后在 show 操作中立即返回?