Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In a GORM findBy* query, how can I use "sort" before limiting using "max"

The following grails query will limit the number of results to 3 and then sort those by id:

def results = Domain.findAllByFoo(foo, [sort: 'id', order: 'desc', max: 3])

So this will return ids 1 through 3, and then reverse their order, so that

results*.id == [3,2,1]

Is there a way to sort first, and limit after, so that

results*.id == [99,98,97]

My current workaround is this:

if (results.size() > max) results = results[0..<max]

like image 354
c089 Avatar asked Feb 14 '12 10:02

c089


1 Answers

This was due to a bug in Grails that is fixed in 2.0.4.

like image 94
c089 Avatar answered Nov 12 '22 06:11

c089