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.
I would use list:
def results = Domain.list(sort: "lastUpdated")
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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With