sort case insensitive in list method of a named query in Grails with MongoDB

1.7k Views Asked by At

Is there a way to specify that a list in a namedquery is case insensitive? I think that before grails 2.2 this was by default, but with Grails 2.2.3 is not working...

This is the line of my code that makes the call to the named query and tries to list sorting in a case insensitive way.

BackendUser.filter(company,filter).list(max:max,offset:offset,"sort":sortName,order:order,ignoreCase:true)

As you can see, I've tried adding the ignoreCase:true option, but it's not working. And I cannot add the sorting in the named query because I use it in other places that need different sorting options.

Just in case it's needed, this is the named query

static namedQueries = {
    filter {company,filter->
        eq 'company',company
        if (filter.firstName){
            ilike 'firstName',"%${filter.firstName}%"
        }
        if (filter.lastName){
            ilike 'lastName',"%${filter.lastName}%"
        }
        if (filter.email){
            ilike 'email',"%${filter.email}%"
        }
    }
}

EDIT: Sorry, I forgot to mention that I'm using MongoDB and I think is this one who's causing the problem

1

There are 1 best solutions below

7
On

Looking here, it seems that you can do it with:

//pass dir to your named query
order(new Order(param, dir=='asc').ignoreCase())