【问题标题】:Grails : Retrieve all latest children recordsGrails:检索所有最新的子记录
【发布时间】:2014-10-10 10:45:30
【问题描述】:

我是 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 的多行。 例如:父母的最新 id 是 7。 子表在父 id 7 上包含近 10 条记录。我想用父 id(7) 的引用检索所有这 10 条记录。

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

【问题讨论】:

    标签: grails grails-orm


    【解决方案1】:

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

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

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

    【讨论】:

    • 感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-25
    • 1970-01-01
    • 2020-10-20
    相关资源
    最近更新 更多