2012-01-17 26 views
0

我的警報實體與這些實體有連接。它們都可以連接成一個大表嗎?這是一對多的關係。而沒有alert_locations,alert_user等Grails控件連接表

class Alerts { 

    static hasMany = [locations:Locations, alertStatus:AlertStatus, users:Users] 
    Date alertDateTime 
    String pest 
    String crop 

    static constraints = { 
     alertDateTime (blank:false) 

     pest (blank:false) 
     crop (blank:false) 
    } 

回答

1

如果您的關係與Alerts場雙向的,然後它會消除連接表,因爲它可以存儲外鍵Alerts每個表中,如需要

class Locations { 
    Alerts alerts 
    ... 
} 

您還可以使用的belongsTo地圖形式,這將增加級聯刪除:

class Locations { 
    static belongsTo = [alerts: Alerts] 
    ... 
}