title: How to set a derived property to lower case in Grails/GORM?
body: <p>This is a newbie question -- thank you for your help. I wanted to set a derived property to lower case in my domain model. Did some search (<a href="http://grails.org/doc/latest/guide/GORM.html#ormdsl" rel="nofollow">http://grails.org/doc/latest/guide/GORM.html#ormdsl</a> plus some other) and I thought the following would work (note: <code>nameLowerCase formula: 'LOWER(NAME)'</code>) ...</p>
  
  <pre>
  class Item {
      String name
      String nameLowerCase
  
      static constraints = {
          name(blank: false)
          nameLowerCase(blank: false, unique: true)
      }
  
      static mapping = {
          nameLowerCase formula: 'LOWER(NAME)'
          sort nameLowerCase: "asc"
      }
  }
  </pre>
  
  <p>However, when I do ...</p>
  
  <pre>
  new Item(name: 'A').save(failOnError: true)
  new Item(name: 'c').save(failOnError: true)
  new Item(name: 'B').save(flush: true, failOnError: true)
  
  println Item.list().nameLowerCase
  </pre>
  
  <p>I was expecting it to print <code>[a, b, c]</code> (turning to lower case in addition to the sorting), but it prints <code>[null, null, null]</code>, and I am unable to figure out why.</p>
  
  <p>What am I doing wrong? Or, is there any other way I can achieve the lower case in my domain class itself for <code>nameLowerCase</code> irrespective of what is passed for the <code>name</code> (other than using the formula in mapping)? Any help will be appreciated.</p>