Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 26th, 2012  |  syntax: None  |  size: 0.34 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Grails - Preventing a recursive one-to-many relationship
  2. class TreeNode {
  3.     String name
  4.     String description
  5.  
  6.     static hasMany = [childNodes: TreeNode]
  7. }
  8.        
  9. static constraints = {
  10.   childNodes(validator: {value, obj, errors->
  11.       if(value.contains(obj) {
  12.         errors.rejectValue('childNodes', 'Cannot contain self')
  13.       }
  14.   }
  15. }