問候,我想命令急切地獲取另一個域類以1:m關係擁有的域對象,但不知道如何執行此操作。當我嘗試使用簡化的項目時,出現錯誤。下面是我的嘗試:在Grails中,我如何訂購渴望獲取的域記錄?
class Picture {
String name
static hasMany = [comments:Comment]
static mapping = {
comments(lazy:false, sort:'content', order:'desc')
}
}
class Comment {
String content
Date dateCreated
static belongsTo = [Picture]
}
現在,測試紀錄println Picture.get(1) as JSON
如何獲取時,我得到以下錯誤:
java.sql.SQLException: Column not found: COMMENTS0_.CONTENT in statement [select comments0_.picture_comments_id as picture1_0_, comments0_.comment_id as comment2_0_ from picture_comment comments0_ where comments0_.picture_comments_id=? order by comments0_.content desc
沒有sort:'content', order:'desc'
,註釋是隨機的順序,但沒有錯誤。
如果你這樣寫:static mapping = {comments sort:'content',order:'desc'}沒有急切的加載。這不行嗎? – superbly 2011-05-10 06:59:39
我沒有嘗試過,但是當我這樣做時,我仍然得到了與之前相同的SQLException。 – Nenotlep 2011-05-10 07:07:36
我想你遇到了一個已知的問題。 http://jira.grails.org/browse/GRAILS-4089。 – superbly 2011-05-10 07:08:25