Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use ilike with Integer in grails

Tags:

grails

groovy

I use EasyGrid plugin and must find values where integer field like '%001%'

initialCriteria {
    ilike('id', "%"+params.id+"%")
}

But ilike doesn't work with Integer. How to do it?

I tried to do:

    initialCriteria {
        ilike('id'.toString(), "%"+params.id+"%")
    }

    initialCriteria {
        ilike('str(id)', "%"+params.id+"%")
    }

but it's not work.

like image 494
user3387291 Avatar asked Apr 07 '14 12:04

user3387291


1 Answers

If id is an integer in the database, then ilike doesn't really make much sense and there is probably a better way to do what you are trying to do (like adding a type field or something to the domain object, and filter by type)

However, you should be able to do something like this (untested):

initialCriteria {
    sqlRestriction "cast( id AS char( 256 ) ) like '%001%'"
}
like image 184
tim_yates Avatar answered Sep 22 '22 01:09

tim_yates