1

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?

rks
  • 451
  • 1
  • 8
  • 16

1 Answers1

2

This will be possible in grails 2.2 using a sqlProjection:

projections {
    sqlProjection 'trim(title) as title', ['title'], [java.sql.Types.VARCHAR]
}
ataylor
  • 64,891
  • 24
  • 161
  • 189
  • Thanks for the update on the enhancement. But it looks bit complicated than needed. The idea of working at the GORM layer is to stay away from the physical table data types so, as a developer I would prefer to issue trim(title) and the framework should be able to figure out the inherent sql type from the table metadata. – rks Nov 06 '12 at 22:57