Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GORM domain class properties default values

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" ...

like image 796
drago Avatar asked Nov 24 '11 11:11

drago


1 Answers

Put it in the domain class itself

class Company {
    String country = "USA"
}
like image 168
Dónal Avatar answered Oct 19 '22 04:10

Dónal