问题
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
}
when I am saving object of incident, it throws exception like Column 'problem_id' cannot be null. what to do?
回答1:
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"
}
来源:https://stackoverflow.com/questions/11077871/belongsto-multiple-domain