Search code examples
grailsgrails-ormprojectioncreatecriteria

how to trim a property in createCriteria


I am trying to trim a projection property but it does not let me do that.

def c = Book.createCriteria()
def books = c.list { 
    projections {
        property ("title")
    }
    def now = new Date()
    between('publishingDate', now-45, now+15)
}

I would like to trim the 'title' field in the criteria but it does not work. Any suggestions?


Solution

  • This will be possible in grails 2.2 using a sqlProjection:

    projections {
        sqlProjection 'trim(title) as title', ['title'], [java.sql.Types.VARCHAR]
    }