gpt4 book ai didi

oracle - 如何在Grails中删除子域行

转载 作者:行者123 更新时间:2023-12-02 15:25:29 24 4
gpt4 key购买 nike

我正在将数据保存到我的参加 session 表以及参加 session 详细信息表中,该表是参加 session 表的子表。但是,当我只想删除一个子表记录时,它给出了一个错误。我不知道该怎么办。我正在使用grails 2.1.0。谁能帮我这个忙吗?!!!这是我的代码如下:

我的父域>>>

class AdtEntryMeeting {
static mapping = {
table('ADT_ENTRY_MEETING')
version(false)
entryMeetingDetails cascade: 'all'
}
String meetingVenue
Date meetingDate = new Date()
String meetingTime
long CREATED_BY=0
Date CREATED_DATE=new Date()
long UPDATED_BY=0
Date UPDATED_DATE=new Date()
static hasMany = [entryMeetingDetails: AdtEntryMeetingDetails]
static constraints = {
meetingVenue(nullable: false, blank: false)
meetingDate(nullable: false)
meetingTime(nullable: false, blank: false)
CREATED_BY(nullable:true)
CREATED_DATE(nullable:true)
UPDATED_BY(nullable: true)
UPDATED_DATE(nullable: true)
}
String toString(){
return id
}
}

我的 child 域>>>
class AdtEntryMeetingDetails {
static mapping = {
table('ADT_ENTRY_MEETING_DETAILS')
version(false)
}
AuditFirm auditPack
AuditorDtl auditor
String meetingSubject
String responsiblePerson
AdtEntryMeeting entryMeeting
static constraints = {
auditPack(nullable: false, blank: false)
auditor(nullable: false, blank: false)
meetingSubject(nullable: false, blank: false)
responsiblePerson(nullable: false, blank: false)
entryMeeting(nullable: false, blank: false)
}
String toString(){
return auditPack
}
}

我要删除的 Action >>>
if(params[isDelete + detailsCounter] == 'delete'){
def entryMeetingDetailsDelete = AdtEntryMeetingDetails.get(Long.parseLong(params[entryMeetingDetailsId + detailsCounter]))
entryMeetingDetailsDelete.delete()
}else{
def entryMeetingDetailsEdit = AdtEntryMeetingDetails.get(Long.parseLong(params[entryMeetingDetailsId + detailsCounter]))
entryMeetingDetailsEdit.properties['auditPack'] = AuditFirm.get(Long.parseLong(params[auditPack + detailsCounter]))
entryMeetingDetailsEdit.properties['auditor'] = AuditorDtl.get(Long.parseLong(params[auditor + detailsCounter]))
entryMeetingDetailsEdit.properties['meetingSubject'] = params[meetingSubject + detailsCounter]
entryMeetingDetailsEdit.properties['responsiblePerson'] = params[responsiblePerson + detailsCounter]
adtEntryMeetingInstance.addToEntryMeetingDetails(entryMeetingDetailsEdit)
}

我得到的错误>>>
deleted object would be re-saved by cascade (remove deleted object from associations)

最佳答案

您应该首先从父级删除引用,然后删除子级

例如

def entryMeetingDetailsDelete = AdtEntryMeetingDetails.get(Long.parseLong(params[entryMeetingDetailsId + detailsCounter]))

adtEntryMeetingInstance.removeFromAdtEntryMeetingDetails(entryMeetingDetailsDelete)
entryMeetingDetailsDelete.delete()

关于oracle - 如何在Grails中删除子域行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28451994/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com