GORM domain class properties default values

drago picture drago · Nov 24, 2011 · Viewed 9.8k times · Source

Maybe a silly question but where/how should I define default values for GORM domain class properties? For example when I'm creating a new Company object instance I want default value for property country to be "USA". I guess I could do it in create controller but it looks kinda dirty. Something like:

def create = { def companyInstance = new Company() companyInstance.properties = params companyInstance.accepted = "USA" ...

Answer

Dónal picture Dónal · Nov 24, 2011

Put it in the domain class itself

class Company {
    String country = "USA"
}