2017-09-05 31 views
0

ProductViewerController.groovy我試圖讓使用Grails和Groovy的標準從postgreySQL基礎數據,但我面臨的問題,同時accesing列表foregin密鑰ID

class ProductViewerController { 

    def index(Integer id) { 
    def result=ProductLoader.createCriteria().list { 
    eq("product_barcode",id) 
    } 

    result.each { 
    notes->println "${notes}" 
    } 
    render(view:'index.gsp') 
} 
} 

ProductLoader.groovy(Model類)

class ProductLoader { 
String store 
double price 
String notes 
static belongsTo =[product_barcode : Product]  
static constraints = { 
    store() 
    price() 
    notes() 

    } 
} 

我試圖讓外國k的基礎上的數據然後EY ID獲得ClassCastException異常:enter image description here

回答

1

物業product_barcode需要與Product

def result = ProductLoader.createCriteria().list { 
    eq("product_barcode", Product.get(id)) 
} 

對象類型進行比較或你加入外部表像

def result = ProductLoader.createCriteria().list { 
    product_barcode { 
     eq("id", id) 
    } 
} 
+0

感謝gregorr它的工作 –

相關問題