Grails GORM/HQL - 从关联中检索数据
我有一个 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 条最新消息。
I have a Blog domain class, which has many messages:
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'
}
}
Message is used also in other places of the application, so association is unidirectional. How can I get 20 latest blog messages, ordered by creation date? By latest blog messages, I mean 20 latest messages which are associated with ANY blog.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
然后你可以像这样获取...
Then you can fetch like this...