2012-06-18 3 views
2

У меня есть 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» не может быть пустым. Что делать?

ответ

5

Попробуйте удалить hasOne на класс Инциденты, проблемы, запросы и заменить его

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

если удалить эти отношения, то это позволит мне каскадное удаление? – sanghavi7

+0

Для удаления каскада попробуйте добавить каскадное сопоставление. Я обновил ответ. –

+0

Да, человек Это работает красиво, thanx – sanghavi7

Смежные вопросы