Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails findAll with sort, order, max and offset?

I want to integrate sort, order, max and offset in a findAll query. The following works fine:

def books = Book.findAll("from Book as b where b.approved=true order by b.dateCreated  desc", [max: max, offset: offset])

But what I want is:

def books = Book.findAll("from Book as b where b.approved=true", [sort: 'dateCreated', order: 'desc', max: max, offset: offset])

This does not work. How do I have to rewrite this?

like image 893
confile Avatar asked Nov 19 '12 08:11

confile


1 Answers

Using "findAllBy" because it supports sort and order.

def results = Book.findAllByTitle("The Shining",
             [max: 10, sort: "title", order: "desc", offset: 100])

Click here for details.

like image 70
Rita Yuan Avatar answered Oct 21 '22 02:10

Rita Yuan