Как разбить на страницы сложные запросы mongoDB в Grails?

У меня есть три доменных класса Author, Comment и Book:

class Author {
String name
static hasMany = [books: Book, comments: Comment]
}

class Book {
static belongsTo = [author: Author]
static hasMany = [comments: Comment]
}

class Comment {
static belongsTo = [book: Book, author: Author] 
}

У меня есть следующий запрос mongoDB, чтобы найти все книги, в которых есть комментарии от данного автора.

Comment.findAllByAuthor(author1).collect {
        it.book
    }.unique().findAll { 
        it != null 
}

Как я могу использовать разбиение на страницы для этого запроса, т. е. разбивать на страницы все книги?


person confile    schedule 11.12.2012    source источник


Ответы (1)


Используйте запрос критериев с книгой вместо комментария:

def c = Book.createCriteria()
def PaginatedBookList = c.list(max: params.max, offset: params.offset) {
    and{
        eq('author',author1)
        isNotNull('comments')
    }
}
person coderLMN    schedule 15.12.2012