Grails 跨多个域类的过滤和排序
我正在使用 grails,但无法找到跨不同域的连接和排序的适当语法。例如,在下面的示例中,我想检索来自(例如)伦敦的所有作者按标题排序的图书数据页。我更喜欢使用 createCriteria,但如果需要,我会使用另一种技术。
class Location {
String city
static hasMany = [authors: Author]
}
class Author {
String name
static belongsTo = [location: Location]
static hasMany = [books: Book]
}
class Book {
String title
static belongsTo = [author: Author]
}
为了澄清,我想要实现的是获得一个图书域类的列表,该列表相当于像
Select Book.title
From Book
Inner Join Author
On Author.name = Book.authorName
Inner Join Location
On Location.city = Author.homeCity
Where Location.city = 'London'
Order by Book.title
“谢谢”这样的东西
I am using grails and I am having trouble finding the appropriate syntax for joining and ordering across different domains. For example, given the example below, I would like to retrieve a page of book data sorted by title for all authors that come from (eg) London. I have a preference for using createCriteria, but will use another technique if needed.
class Location {
String city
static hasMany = [authors: Author]
}
class Author {
String name
static belongsTo = [location: Location]
static hasMany = [books: Book]
}
class Book {
String title
static belongsTo = [author: Author]
}
To clarify, what I want to achieve would be to get a list of book domain classes that is equivalent to something like
Select Book.title
From Book
Inner Join Author
On Author.name = Book.authorName
Inner Join Location
On Location.city = Author.homeCity
Where Location.city = 'London'
Order by Book.title
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要创建更复杂的数据库查询,您可以使用 [criteria 对象][1] 或 [Hibernate 查询语言 (HQL)][2]。第二种方式更强大,但不太舒服。
[1]: http ://grails.org/doc/latest/guide/5.%20Object%20Relational%20Mapping%20(GORM).html#5.4.2 标准
[2]:http://grails.org/doc/latest/guide/ 5.%20Object%20Relational%20Mapping%20(GORM).html#5.4.3 Hibernate 查询语言 (HQL)
For creating more complex database queries you can use [criteria objects][1] or [Hibernate Query Language (HQL)][2]. Second way is more powerful but less comfortable.
[1]: http://grails.org/doc/latest/guide/5.%20Object%20Relational%20Mapping%20(GORM).html#5.4.2 Criteria
[2]: http://grails.org/doc/latest/guide/5.%20Object%20Relational%20Mapping%20(GORM).html#5.4.3 Hibernate Query Language (HQL)