【发布时间】:2012-09-07 05:26:41
【问题描述】:
我有三个域模型Type1、Type2和Details,关系如下:
class Type1 {
static hasMany = [detail: Detail]
}
class Type2 {
static hasMany = [detail: Detail]
}
class Detail {
Type1 type1
Type2 type2
static belongsTo = [Type1, Type2]
static constraints = {
type1(nullable:true)
type2(nullable:true)
}
}
问题是当Type1 被转换为Type2 时,我无法将Type1.detail 转换为Type2.detail(注意:Type1 和 Type2 只是@987654329 的子代@)。换句话说(在控制器中):
Type1 type1 = Type1.get(params.id)
List type1Details = Detail.findAllByType1(type1)
type1.detail.clear()
Type2 type2 = new Type2()
// transfer other properties of type1 to type2
type1Details.each { type2.addToDetail(it) }
if(type2.save(flush:true) {
type1.save(flush:true)
type1.delete(flush:true)
}
问题是,只更新type1Details,如何设置type1Details*.type1 = null和type1Details*.type2 = type2?
【问题讨论】:
标签: grails grails-orm cascade