Grails:如何在多对多的映射中查询对象?
发布时间:2020-12-14 19:00:53 所属栏目:资源 来源:网络整理
导读:你好我有以下的域类. class Student { int age static hasMany = [courses:Course]}class Course { String name static hasMany = [students:Student]} 我想找到7岁的学生参加课程(id 1). 我可以使用动态查找器或标准构建器或HQL来执行此操作吗? 我不想做以
你好我有以下的域类.
class Student { int age static hasMany = [courses:Course] } class Course { String name static hasMany = [students:Student] } 我想找到7岁的学生参加课程(id 1). 我可以使用动态查找器或标准构建器或HQL来执行此操作吗? 我不想做以下工作,因为它加载所有的学生如此低效: def course = Course.get(1); course.students.findAll{ it.age == 7 } 解决方法def studs = Student.withCriteria { eq('age',7) courses { eq('id',1) } } 在GORM doc,“查询协会”部分. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |