Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>While "deep validation" currently isn't documented for the <a href="http://grails.org/doc/1.3.5/ref/Domain%20Classes/validate.html" rel="noreferrer"><code>validate()</code></a> and <a href="http://grails.org/doc/1.3.5/ref/Domain%20Classes/save.html" rel="noreferrer"><code>save()</code></a> methods, it <a href="http://jira.codehaus.org/browse/GRAILS-4740" rel="noreferrer">will be in future</a> (the document states that the documentation has been missing, while being relevant for the complete 1.3.x tree). The documentation on these methods' <code>deepValidate</code> parameter then <a href="https://github.com/grails/grails-doc/commit/69d3e3b43ff9599bd772" rel="noreferrer">will state</a>:</p> <blockquote> <p>@deepValidate@ (optional) - Determines whether associations of the domain instance should also be validated, i.e. whether validation cascades or not. This is @true@ by default - set to @false@ to disable cascading validation.</p> </blockquote> <p>Tests, however, show that "deep validation" is <strong>not</strong> performed in any of these cases:</p> <ul> <li>one-to-one associations</li> <li>one-to-many associations <ul> <li>associated objects assigned using the matching setter</li> <li>associated objects assigned using the matching <code>addTo*(..)</code> method, e.g., <code>person.addToAddresses(..)</code></li> </ul></li> <li>using both the <code>validate()</code> and <code>save()</code> methods, <ul> <li>and also, using both methods with an explicit <code>deepValidate: true</code> parameter</li> </ul></li> </ul> <p><a href="http://grails.1312388.n4.nabble.com/no-validation-or-failOnError-for-cascades-td2122537.html" rel="noreferrer">Similar findings have been published at another place</a>, categorizing the "non-behavior" as a "known issue". My own, comprehensive, test cases can be <a href="http://rapidshare.com/files/431821513/deepValidateTests.zip" rel="noreferrer">downloaded from here</a>.</p> <p>The <strong>solution</strong>, finally, is to manually invoke validation on the child object:</p> <pre><code>class Person { Address primaryAddress static hasMany = [secondaryAddresses: Address] static constraints = { primaryAddress validator: { it?.validate() } secondaryAddresses validator: { it?.every { it?.validate() } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload