Drools: how to insert a fact after verification, if it is not already present in working memory

I use drools to verify an object. The object also has a getChildrenList () method, which returns the child objects associated with this object (master-detail relation).

I do some checks for the object, and then I want to check the child objects as well, so I also insert all the child objects into the working memory using the 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 start if the children are already inserted. I mean, because I'm changing some fact that the rule is firing again. How can I prevent this?

thanks

+4
source share
1 answer

You can try adding this line to the when condition, although I suspect that this is not the β€œcorrect” idiom:

 not( Child(this == $ch) ) 
+2
source

All Articles