我有一个培训域类
class Training {
String type
Date createdOn
Date modifiedOn
static belongsTo = [course: Course]
static hasMany = [attachments: Attachment]
}
我有课程领域课程
class Course {
String name
static hasMany = [trainings: Training, tracks: Track]
static belongsTo = Track
}
和跟踪域类
class Track {
String name
}
我想根据曲目选择培训。
现在说我得到了跟踪ID,我想根据Track id
检索培训我尝试过像这样的查询
def query = "FROM Training AS t WHERE t.course.tracks.id IN (1,2)"
trainingList = Training.findAll(query)
它给出了
illegal attempt to dereference collection
错误..因为我无法做t.course.tracks.id
帮助我编写正确的hql查询以获得培训,如果我有跟踪ID(比如1,2)
答案 0 :(得分:0)
你能做的就是这个
def query = "FROM Training AS t join t.course as c join c.tracks as tr WHERE tr.id IN (1,2)"
trainingList = Training.findAll(query)
问题是当你试图从一个到多个。
答案 1 :(得分:-1)
请在下面找到HQL以检索tracid 1&的所有培训。 2。
来自课程c,Track tr,Training t其中tr.courceid = c.courceid和 tr.trackid = c.tracid和tr.trackid in(1,2)