Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Grails GORM/HQL-从关联中检索数据_Grails_Hql_Gorm - Fatal编程技术网

Grails GORM/HQL-从关联中检索数据

Grails GORM/HQL-从关联中检索数据,grails,hql,gorm,Grails,Hql,Gorm,我有一个Blog域类,其中包含许多消息: class Blog { String description static hasMany = [messages : Message] static belongsTo = [owner : User] static constraints = { description blank: true, nullable: true } } class Message { Strin

我有一个Blog域类,其中包含许多消息:

class Blog {

    String description

    static hasMany = [messages : Message]
    static belongsTo = [owner : User]

    static constraints = {
        description blank: true, nullable: true
    }
}

class Message {

    String content
    String title
    User author

    Date dateCreated
    Date lastUpdated

    static hasMany = [comments : Comment]

    static constraints = {
        content blank: false
        author nullable: false
        title nullable: false, blank: false
    }

    static mapping = {
        content type: "text"
        sort dateCreated: 'desc'
    }
}
消息也用于应用程序的其他位置,所以关联是单向的。我如何获得20条最新的博客信息,按创建日期排序?所谓最新的博客消息,我指的是20条与任何博客相关的最新消息

def latestMessages = Message.listOrderByDateCreated(max:20, order:"desc")
然后你就可以这样拿

BlogMessage.list([max:20])

这很好,但是还有其他类也与Message关联,我只想要那些与blog关联的消息。我在想,除了继承,可能还有其他方法来实现我的目标。
BlogMessage.list([max:20])