【问题标题】:Grails Filtering and Ordering across Multiple Domain classes跨多个域类的 Grails 过滤和排序
【发布时间】:2011-02-19 15:14:20
【问题描述】:

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

谢谢

【问题讨论】:

    标签: grails join grails-orm


    【解决方案1】:

    要创建更复杂的数据库查询,您可以使用 [条件对象][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.3Hibernate 查询语言 (HQL)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-14
      • 1970-01-01
      相关资源
      最近更新 更多