How do I handle an empty List in Grails/GORM? -


I am trying to create multiple relationships with grails / gorm. I do not know how to handle empty lists.

This is my domain class:

  class guardian {list is stable in children = [children: child}}   < / P> 

This is my test:

  zero testEmptyChildren () {def parent = new parent () 0, parent.children.size ()}  

This "fails with java.lang.NullPointerException: The size of the method can not come on the tap object (") "

What should I do to handle an empty list?

Parents in their tests. Children will always be unwell (children will not be started until you add one before) so you can change your test to:

  assertNull parent.children  

When you want to save your parents, children will be started (even if children are added) or when children are added. If you wish, you can manually do it yourself while defining children to get it started:

  list & lt; Children & gt; Children = new array list & lt; Children & gt; ()  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -