我是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/