gpt4 book ai didi

grails - Grails:检索所有最新的子记录

转载 作者:行者123 更新时间:2023-12-02 14:42:38 25 4
gpt4 key购买 nike

我是Grails的新手,我遇到一些问题,如下所述。

我有2个域类:父级和子级。我将数组的数组存储到数据库中。

家长类是:

class Parent{
static hasMany = [child: Child]
}

子类是:
class Child {

String time
String record
String value
static belongsTo= [parent: Parent]

static constraints = {
time(blank: false)
record(blank: false)
belongsTo(blank: false)
}
}

现在我的要求是:

我需要检索包含数据库中具有唯一父ID的多行的 child 的最新记录。
例如: parent 的最新ID为7。
子表包含父ID为7的近10条记录。我想引用父ID(7)检索所有这10条记录。

请有人帮忙编写代码/查询。

最佳答案

gorm是一个很棒的ORM,您可以使用以下代码:

def parent = Parent.get(7)
def childList = Child.findAllByParent(parent);

阅读 this,它将帮助您更好地了解 gorm

关于grails - Grails:检索所有最新的子记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26297626/

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