我有像这样的Grails Domain Class
class ClassRoom {
Integer Id
String classRoomName
Date dateDeleted
static hasMany = [students: Student]
}
class Student {
String studentName
Date dateDeleted
}
假如我从ClassRoom打印classRoom 1的所有学生。
println ClassRoom.findByIdAndDateDeletedIsNull(1).students
它将打印所有有dateDeleted的学生。
有没有办法过滤掉dateDeleted SET的记录?
答案 0 :(得分:2)
以下将返回学生名单
ClassRoom.executeQuery("""
select s
from ClassRoom c
join c.students s
where c.id = :id
and c.dateDeleted is null
and s.dateDeleted is null
""", [id: id])
答案 1 :(得分:1)
过滤结果:
ClassRoom.findByIdAndDateDeletedIsNull(1).students.findAll{!it.dateDeleted}