Question

It looks like a basic issue, that I am trying to test Grails constraints in groovy console tool.

Does it work only when I do any database CRUD operations?

Sample code is like this

class AAA{
    String a
    String b
    static constraints = {
         a size:5..8
         b nullable:false
    }
}

def x = new AAA(a:'sss',b:null)
println x.a
println x.b

Output is

sss
null

Why are they not working?

Était-ce utile?

La solution

Yes because the object.validate() method is only going to validate these constraints before saving the object.According to the official documentation of grails .

Constraints provide Grails with a declarative DSL for defining validation rules, schema generation and CRUD generation meta data. .See below

http://grails.org/doc/2.3.x/ref/Constraints/Usage.html

Autres conseils

there is a wiki about gorm access and validation trought grails console in this url you may find some help here

Looks like one need to stop and run-app again, when using grails console.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top