tags:

views:

552

answers:

1

Hi All,

I am using drools to validate an object. The object also has a getChildrenList() method which returns the child objects related to this object (master-detail relation).

I do some validations on the object and then I want to validate the child objects as well, so I insert all of the child objects as well into the working memory by using following rule:

 rule "Insert Children"
     when
             $parent : Parent ( eval(childrenList != empty) )
                     $ch : Child() from $p.childrenList
     then
             insert($ch);
     end

Now how can I make sure that this rule does not get fired if the children were already inserted. I mean because I modify some fact the rule gets re-fired. How can I prevent that?

Thanks

A: 

You could try adding this line to the when condition, although I suspect that this is not the 'right' idiom:

not( Child(this == $ch) )
Peter Hilton
No that seems fine - do something like that. Or you can use a flow group or something to make sure you only do this up front...
Michael Neale