gpt4 book ai didi

hibernate - 在Grails 3中按WHERE子句过滤hasMany结果

转载 作者:行者123 更新时间:2023-12-02 14:59:44 24 4
gpt4 key购买 nike

我有这样的grails域类

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的记录?

最佳答案

以下将返回给您的学生列表

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])

关于hibernate - 在Grails 3中按WHERE子句过滤hasMany结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48530524/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com