grailsgrails-3.3

Grails domain property nullable - true by default?


Regarding setting a domain class property to be nullable, as described here: https://docs.grails.org/3.3.10/ref/Constraints/nullable.html

Is there a way to make "nullable equals true" to be the default for all properties in all my Grails domain classes? As opposed to the default for nullable being false.

As an additional note, I also have the property grails.databinding.convertEmptyStringsToNull = false in my application.yml file.

I'm on Grails 3.3.10.


Solution

  • You can define default constraints for all domain classes in grails-app/conf/application.groovy.

    grails.gorm.default.constraints = {
        '*'(nullable: true)
    }
    

    See the Sharing Constraints section of the docs for more details.