【发布时间】:2011-04-13 11:52:29
【问题描述】:
我有一个博客域类,它有很多消息:
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 条最新消息。
【问题讨论】:
标签: grails hql grails-orm