属于多个域 [英] belongsTo multiple Domain
本文介绍了属于多个域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有4个类,事件,问题,请求,另外一个是附件.
I have 4 classes, incidents,problems, requests and another is Attachment.
每个域都看起来像.........
Every domain look like.........
Class Incidents
{
// other fields
static hasOne = [attachment: Attachment]
static constraints = [attachment nullable:true]
}
Class Problems
{
// other fields
static hasOne = [attachment: Attachment]
static constraints = [attachment nullable:true]
}
Class Requests
{
// other fields
static hasOne = [attachment: Attachment]
static constraints = [attachment nullable:true]
}
Class Attachment
{
// other fields
static belongsTo= [
incident: Incidents,
problem: Problems,
requests: Requests
]
static constraints = {
incident nullable: true
problem nullable: true
requests nullable: true
}
当我保存事件对象时,它会引发异常,例如列'problem_id'不能为null. 该怎么办?
when I am saving object of incident, it throws exception like Column 'problem_id' cannot be null. what to do?
推荐答案
尝试删除有关事件,问题,请求的hasOne并将其替换为
Try to remove the hasOne on Class Incidents, Problems, Requests and replace it with
Attachment attachment
static constraints = {attachment: unique: true, nullable:true}
static mapping = {
attachment cascade: "delete"
}
这篇关于属于多个域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文