在 Grails 中,如何订购急切获取的域记录?
您好,我想订购另一个域类以 1:m 关系拥有的急切获取的域对象,但不知道如何执行此操作。当我尝试使用简化的项目时,出现错误。以下是我的尝试:
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) 作为 JSON
获取记录时,我收到以下错误:
java.sql.SQLException: 未找到列:语句中的 COMMENTS0_.CONTENT [从 picture_comment comments0_ 中选择 comments0_.picture_comments_id 作为 picture1_0_, comments0_.comment_id 作为 comment2_0_ 其中 comments0_.picture_comments_id=? order by comments0_.content desc
如果没有sort:'content', order:'desc'
,评论将按随机顺序排列,但不会出错。
Greetings, I would like to order eagerly fetched domain objects that another domain class owns in a 1:m relationship, but cannot figure how to do this. When I try with a simplified project, I get an error. Below are my attempts:
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]
}
Now, when testing how the record fetch with println Picture.get(1) as JSON
, I get the following error:
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
Without sort:'content', order:'desc'
, the Comments are in random order but no error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终在获取了孩子列表后进行了排序,当时我在代码中需要它们。像这样的东西:
具有允许根据需要进行无限排序配置的优点,而不是默认情况下仅检索一个。
I ended up doing the ordering after the list of children was already fetched, at the time I need them in the code. Something like this:
Has the advantage of allowing unlimited sorting configurations as needed, as opposed to only one as retrieved by default.