2012-01-14 234 views
0

我在Grails中有以下实体警报和位置。但我似乎无法将位置添加到alert_location表。该错误是缺少方法异常。请帮助。Grails实体关系

class Alerts { 


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


    static constraints = { 
     alertDateTime (blank:false) 
     pest (blank:false) 
     crop (blank:false) 
    } 

class Locations { 


    static hasMany = [ farms:Farms, reports:Reports, reportMessages:ReportMessages] 

    String locationName 
    String locationXY 

    static constraints = { 

     locationName (blank:false) 
     locationXY (blank:false, unique:true) 
    } 
} 

在我的代码,

Locations loc = new Locations(); 
    loc.locationName = 'a' 
    loc.locationXY = 'aa' 
    loc.save() 
    Alerts a = new Alerts() 
    Date d = new Date() 
    a.alertDateTime =d 
    a.crop ="o" 
    a.pest ="c" 
    //a.save() 
    println loc.locationName 
    loc.addToAlerts(a) 
    a.save() 

回答

0

,而不是因为你使用a.save()尝试a.addToLocations(loc)。否则做loc.save()