Grails GORM 使用 HQL 查询关联的多方
我的课程和类别之间存在一对多关系,
class Course {
String code
static hasMany = [categories:CourseCategory]
}
Class CourseCategory {
String name
}
我需要根据类别列表查询课程。我已经尝试过查询
courseInstanceList = Course.findAll("from Course c inner join c.categories cts where cts.id in :categoryIds",[categoryIds:categoryIds])
,但此查询返回课程和课程类别 - 只是想知道如何创建查询以仅返回课程?
I have a one to many relationship between a Course and Categories
class Course {
String code
static hasMany = [categories:CourseCategory]
}
Class CourseCategory {
String name
}
I need to query courses based on a list of categories. I have tried the query
courseInstanceList = Course.findAll("from Course c inner join c.categories cts where cts.id in :categoryIds",[categoryIds:categoryIds])
But this query returns both Courses and CourseCategories - just wondering how to create a query to just return courses?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 createCriteria 方法:
You can use the createCriteria method:
差不多三年过去了……)
无论如何,答案是:
只获取类别:
Almost three years past ... )
Anyway here's the answer:
to get just categories: