gpt4 book ai didi

grails - 属于多个域

转载 作者:行者123 更新时间:2023-12-02 13:49:23 25 4
gpt4 key购买 nike

我有 4 个类、事件、问题、请求,另一个是附件。

每个域名看起来都像.........

    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
}

当我保存事件对象时,它会抛出异常,例如 Column 'problem_id' cannot be null。怎么办?

最佳答案

尝试删除 Class Incidents, Problems, Requests 上的 hasOne 并将其替换为

   Attachment attachment
static constraints = {attachment: unique: true, nullable:true}
static mapping = {
attachment cascade: "delete"
}

关于grails - 属于多个域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11077871/

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