Search code examples
grailssql-order-bygrails-orm

How to order by more than one field in Grails?


Is there a way to get a list ordered by two fields, say last and first names?

I know .listOrderByLastAndFirst and .list(sort:'last, first') won't work.


Solution

  • This old solution no longer works. Please see mattlary's answer below

    You may have to write a custom finder in HQL or use the Criteria Builder.

    MyDomain.find("from Domain as d order by last,first desc")
    

    Or

    def c = MyDomain.createCriteria()
    def results = c.list {
           order("last,first", "desc")
    }