Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grails default constraints

Tags:

grails

groovy

Assume I have a Grails domain object like this:

class Todo {

    String name
    String status

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

What are the default constraints on a field if:

  • It's listed in the constraints block e.g. name
  • It isn't listed in the constraints block, e.g. status
like image 308
Dónal Avatar asked Mar 23 '09 15:03

Dónal


People also ask

What are Grails constraints?

Constraints provide Grails with a declarative DSL for defining validation rules, schema generation and CRUD generation meta data. For example, consider these constraints: class User { ... static constraints = { login size: 5.. 15, blank: false, unique: true password size: 5..

What is Grails domain class?

A domain class fulfills the M in the Model View Controller (MVC) pattern and represents a persistent entity that is mapped onto an underlying database table. In Grails a domain is a class that lives in the grails-app/domain directory.


2 Answers

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]
like image 92
Ted Naleid Avatar answered Sep 23 '22 12:09

Ted Naleid


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

like image 24
Siegfried Puchbauer Avatar answered Sep 22 '22 12:09

Siegfried Puchbauer