2017-06-12 11 views
1

ドメインプロパティで検証が行われているが、関連する(hasMany)プロパティで検証されていないケースがある。Grails domain hasMany validation

両方のプロパティ(domainおよびhasMany)で検証を有効にするために追加できる設定はありますか。

Grailsのバージョン:3.1.14

Example: 

class Person { 
     String name; 
     static hasMany = [location: Location] 
     static constraints = { 
     name nullable: true 
     } 
} 

class Location { 
     String address 
     String city 
     State state 
     String zip 

     static constraints = { 
     address nullable: true 
     } 
} 
+0

あなたはGrailsのどのバージョンを使用していますか?これをあなたの質問に含めると便利です。 –

+0

grails 3.1.14 投稿も編集されています –

+0

https://schneide.wordpress.com/2010/09/20/gorm-gotchas-validation-and-hasmany/このようなものが必要です – Vahid

答えて

1

あなたが望むよう検証があり、多くの団体のために働く必要がありますドキュメントによると:http://docs.grails.org/3.1.14/ref/Domain%20Classes/validate.html

をしかし、私のテストの中で、それはeather動作しません。

他のソリューションは、制約で動作するようです:

static constraints = { 
    name nullable: true 
    location validator: {val, obj -> 
     val.every { it.validate() } ?: 'invalid' 
    } 
} 
+0

ここに記載されているものと同じです: https://stackoverflow.com/questions/16181599/grails-validate-nested-command-object-not-working – gregorr

+0

ありがとうございました。私は、Persistence Listenerレベルで "hasMany"バリデーターを呼び出す提案に近いものを試しました。 –