2017-09-05 29 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它的工作 –

相关问题