S.P.
S.P.

Reputation: 2564

How can I do an order by desc in createCriteria?

I'm getting a list of the data that I have stored in my column 'age'. What I want to do is to do an order by desc, but I have no idea how I can do it.

My code:

def c = Config.createCriteria()
def checkAge = c.list  {
    projections {                    
        property('age')
    }
}

Upvotes: 1

Views: 1144

Answers (2)

dmahapatro
dmahapatro

Reputation: 50265

def c = Config.createCriteria()
def checkAge = c.list  {
   projections {                    
       property('age')
   }
   order 'age', 'desc'
}

Refer createCriteria for details.

Upvotes: 4

jnunderwood
jnunderwood

Reputation: 101

You can do this with a parameter to your call to list:

c.list(order: 'desc') { ... }

See The Grails Guide for more details.

Upvotes: 0

Related Questions