我有一个培训 Realm 类(class)
class Training {
String type
Date createdOn
Date modifiedOn
static belongsTo = [course: Course]
static hasMany = [attachments: Attachment]
}
我有类(class) Realm 类(class)
class Course {
String name
static hasMany = [trainings: Training, tracks: Track]
static belongsTo = Track
}
和跟踪域类
class Track {
String name
}
我想选择基于轨迹的训练。
现在说我得到了轨道ID,我想根据轨道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
如果我有曲目ID(例如1、2),请帮助我编写正确的hql查询以获得培训
最佳答案
你能做的就是这个
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)
问题是,当您尝试从一个变为多个时。