I am trying to get grails to check the contents of a list of objects, it might be easier if you show the code first:
class Item { Contact recipient = new Contact() List extraRecipients = [] static hasMany = [ extraRecipients:Contact ] static constraints = {} static embedded = ['recipient'] } class Contact { String name String email static constraints = { name(blank:false) email(email:true, blank:false) } }
Basically, I have the only Contact ('recipient') required, this works fine:
def i = new Item() // will be false assert !i.validate() // will contain a error for 'recipient.name' and 'recipient.email' i.errors
What I would like to do also checks any of the attached Contact objects in "extraRecipients" in such a way that:
def i = new Item() i.recipient = new Contact(name:'a name',email:' email@example.com ')
Is it possible or just need to extraRecipients over the collection in my controller and call validate() for each object in extraRecipients ?
source share