Grails过滤和排序多个域类

时间:2011-02-19 15:14:20

标签: grails join gorm

我正在使用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

由于

1 个答案:

答案 0 :(得分:1)

要创建更复杂的数据库查询,可以使用[criteria objects] [1]或[Hibernate Query Language(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)

相关问题