tags:

views:

476

answers:

2

Hi,

Assume I have a Grails domain object like this:

class Todo {

    String name
    String priority
    String status

    static constraints = {
        name(blank: false)
        priority()
    }    
}

What are the default constraints on a field if:

  • It's listed in the constraints block without any actual contraints, e.g. priority
  • It isn't listed in the constraints block, e.g. status

Thanks, Don

+4  A: 

As far as I know it is only nullable: false in both cases.

Siegfried Puchbauer
+6  A: 

Yep, Siegfried is right, nullable: false is the only thing that gets set by default. You can take a look at the domain class artefact and interrogate the constrained properties in the console:

grailsApplication.getDomainClass("Todo").constrainedProperties.each { propName, constraints  ->
    println "$propName : ${constraints.appliedConstraints.name}"
}

Prints:

status : [nullable]
priority : [nullable]
name : [blank, nullable]
Ted Naleid