Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails 2.3.4 Sorting / FindAll Changes

Tags:

sorting

grails

In my application, I had been sorting my domain object as follows:

def o = Domain.findAll(sort: 'lastUpdated')

In Grails 2.2.* , this was working fine and the results were being returned. Today, I upgraded to Grails 2.3.4, and that same syntax is throwing an error, stating that:

No property found for name [all] for class [sample.Domain]

What's the new syntax for sorting?

Thanks in advance.

like image 656
meoww- Avatar asked May 11 '26 03:05

meoww-


2 Answers

I would use list:

def results = Domain.list(sort: "lastUpdated")

like image 147
zoran119 Avatar answered May 12 '26 20:05

zoran119


About the last comment, it could create a pretty bad performances issue:

With Domain.findAll().sort({lastUpdated: 'desc'}) you load the entire table before sorting anything. It looks ok for this request, but assuming that you have tons of data you would want to add a maximum and an offset. The request would take too much time otherwise.

On the other hand, the one above is much better:

def results = Domain.list(sort: "lastUpdated")

Doing so, you load only the amount of data you need... nothing more, nothing less. You can this way add an offset and a maximum of rows:

def results = Domain.list(max: 10, offset:10, sort: "lastUpdated")

It is not an answer to the original post, but it explains why the previous comment had a bad vote :)

like image 33
Loic Cara Avatar answered May 12 '26 20:05

Loic Cara