How can i set default value in grails domain class

后端 未结 3 1401
遥遥无期
遥遥无期 2021-02-05 00:27

Is there any way to set a default value to domain class property? I have a class called PayMethod, where I want the name property to default to \

3条回答
  •  渐次进展
    2021-02-05 00:39

    This will be possible in 2.2 which should be released this week or next. See http://jira.grails.org/browse/GRAILS-5520 for the relevant feature request. The syntax will be

    static mapping = {
       name defaultValue: "'Cash'"
    }
    

    For now you'll need to do what you're doing - set the value as the default value of the field. You can manually update the database schema, or do the work as part of a migration.

提交回复
热议问题