In a GORM query, findBy *, how can I use "sort" to limit the use of "max",

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

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

This way, it will return identifiers 1 through 3, and then change their order, so that

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

Is there a way to sort first and restrict it so that

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

My current workaround is this:

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

+6
source share
1 answer

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

+2
source

Source: https://habr.com/ru/post/908418/


All Articles