【问题标题】:Searching association table using criteria使用条件搜索关联表
【发布时间】:2009-11-09 16:44:43
【问题描述】:

我有以下 grails 域(示例):

// a member of the library
class LibraryUser {
    string name
}

// a book
class Book {
    string title
    string author
}

// association which user currently has which book checked out
class Checkout {
     LibraryUser user
     Book        book
}

如何检索给定用户当前已签出的按字母顺序排序的图书列表? (使用条件查询)

一个类似的问题是,如果我没有明确地对 Checkout 表进行编码,而是使用 has-many:

// a member of the library
class LibraryUser {
    string name

    static hasMany = [ books : Book ]
}

// a book
class Book {
    string title
    string author
}

如何在此处使用条件查询来检索给定用户的所有当前已签出书籍的按字母顺序(!)排序的列表?

【问题讨论】:

    标签: grails


    【解决方案1】:

    我认为您需要将关联从 Book 映射到 Checkout 以便您可以这样做:

    Book.createCriteria().list{
        checkouts{
            eq('user', someuser)
        }
        order('title')
    }
    

    【讨论】:

    • 是的,这行得通。但是由于其他原因(例如问题 1702369 和 1706189),映射目前对我不起作用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-07
    • 1970-01-01
    • 2011-06-23
    • 1970-01-01
    • 2011-06-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多