我在Grails中有两个实体,它们具有一对多的关系Location和LocationImage
class Location {
Long phone;
String url;
static hasMany = [locationImage: LocationImage]
static constraints = {
phone(blank: true, nullable: true)
url(blank: true, nullable: true)
locationImage(nullable: true)
}
}
class LocationImage {
String description
String path
static belongsTo = [location:Location]
static constraints = {
description(blank:true,nullable:true)
}
}
如何通过外键位置ID在locationImage表中找到路径属性?
好了,我解决了,这就是我所需要的
def getLocationImage(String locationName){
def location = Location.findByName(locationName)
def locationImage = LocationImage.createCriteria().list{
and {
eq('location',location)
}
}
return locationImage.path
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句