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:
constraints
block e.g. nameconstraints
block, e.g. statusConstraints 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..
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.
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]
As far as I know it is only nullable: false
in both cases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With