grails - Sorting on nullable fields in GORM -


i'm trying figure out how sort on multiple fields in grails 3, 1 of may or may not null. have book domain:

class book {      string title     string sorttitle      static constraints = {         title blank: false         sorttitle nullable: true     } } 

books titles "the peripheral" have sorttitle of "peripheral, the", otherwise sorttitle null. want books sorted sorttitle if 1 exists, otherwise title.

i found other similar questions, none nullable field. happen have pointers in right direction?

you can use:

coalesce(book.sorttitle, book.title)

here have official hibernate documentation.


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -