문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top