Grails 跨多个域类的过滤和排序

发布于 2024-10-18 07:47:36 字数 675 浏览 4 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

许久 2024-10-25 07:47:36

要创建更复杂的数据库查询,您可以使用 [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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文