我试图从我的数据库中删除一个更复杂的相关对象,所以我使用 grails 控制台进行了调查并想出了这个:
TextContent textContent = ...The item to delete...
// TextContent hasMany BundleText
// BundleText belongsTo BundleVersion
textContent.bundleTexts.each {
BundleVersion bundleVersion = it.bundleVersion
bundleVersion.removeFromBundleTexts(it)
textContent.removeFromBundleTexts(it)
it.delete()
//bundleVersion.save()
}
// Language hasMany TextContent
// Language belongsTo textContent (?)
textContent.language.removeFromTextContents(textContent)
// TextContent belongsTo textCode
TextCode textCode = textContent.textCode
textCode.removeFromTextContents(textContent)
textContent.delete()
//textCode.save()
现在这一切在 grails 控制台中运行良好,所以我把它放在我的数据库服务中,然后运行应用程序。该应用程序成功运行该方法(已验证),但是当它重新读取集合时,它再次出现.. 大谜团......!?
有人见过类似的吗?还是我只是令人尴尬的幼稚?
编辑
为了澄清:
class TextCode {
static hasMany = [ textContents : TextContent ]
}
class TextContent {
Language language
static belongsTo = [ textCode : TextCode ]
static hasMany = [ bundleTexts : BundleText]
}
class BundleText {
TextContent textContent
static belongsTo = [ bundleVersion : BundleVersion ]
}
class Language {
static hasMany = [ textContents : TextContent ]
}