Showing posts with label default value of domain fields. Show all posts
Showing posts with label default value of domain fields. Show all posts

Monday, May 5, 2014

Setting default value for fields in Grails Domain Class


class MyDomainClass {
    Date myDate = new Date();
    Boolean myBoolean = false;
    String myString = "";

    static mapping = {
        myDate defaultValue: "now()"
        myBoolean defaultValue: "false"
        myString defaultValue: ""
    }
}

You can use sql now() method rather than Java/Groovy new Date()