Closed danhyun closed 10 years ago
We will need to investigate this, but the associations should be validated as well automatically, as described in the Grails reference guide. You'll see that the deepValidate
option defaults to true
.
Thanks for the response, I tried both null map and deepValidate: true
versions of user.validate
and still could not get it to validate the profile object. Please let me know if you need my version of hubbub to reproduce if you cannot reproduce in 2.3.4.
I uncovered what the issue here is: the hasOne
on User
cascades saves, but it does not cascade validation. To get validation across associations, you need a belongsTo
on the other side. I have made a note of this in the manuscript and updated the sample source code.
Using Grails 2.3.4
The listing should also validate against
user.profile
The
register.gsp
should also be updated to list the validation errorsI had to return
profile
as a top level key because<g:hasErrors/>
was not picking it from theuser
object. I'm sure there's a better way to do this but without profile validation, theregister
action will only validate theuser
object and fail ifprofile
does not validate causing an exception to be thrown as well as storinguser
sansprofile
.One more consideration is that the
profile
object having a nulluser
will crop up as an error. To the end user this is meaningless so hopefully there is a way to blacklist this error.PS: This updated register code will fix the null user on profile object validation
This messy code can be used to gain an even greater appreciation for the
Command
objects for data binding and validation.