应用信息:
我的域名类:
class AgePhase {
String agePhase
static hasMany = [assessors: Assessor]
其他域类:
class Assessor {
static belongsTo = [AgePhase]
static hasMany = [agePhase: AgePhase]
在我的数据库中,我有Assessor,AgePhase和join assessor / agePhase表。
如何根据agePhase ID和Assessor ID从assessor / agePhase表中删除记录?
答案 0 :(得分:0)
你需要调用removeFrom
对象上的AgePhase
(因为它属于这个类)并给出一个Assessor对象作为参数。
示例:强>
def agePhase = AgePhase.get(agePhaseId)
def assessor = Assessor.get(assessorId)
agePhase.removeFromAssessors(assessor)
这将删除agePhaseId和assessorId
的连接表中的条目答案 1 :(得分:-1)
如果要根据 agePhaseId 和 assessorId 从关系表中删除记录,可以尝试以下操作:
def agePhase = AgePhase.get(agePhaseId)
def assesor = agePhase.assessors.find{ it.id == assessorId }
agePhase.removeFromAssessors(assesor)
Grails文档中的参考:removeFrom