에서 데이터를 검색 나는 많은 메시지가있는 블로그 도메인 클래스가 있습니다Grails는 GORM/HQL은 협회
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 개의 최신 메시지를 의미합니다.
내 목표를 달성하기 위해 상속보다 다른 방법이 있다고 생각했습니다. – jjczopek
더 좋은 아이디어가 나오지 않았기 때문에 대답을 수락합니다. – jjczopek