I'm using the drools 6 engine. Suppose I have an account object that has a collection of sections and each section has a status flag that can be "GOOD" or "BAD". If I was to write the following:
rule "Check if account has a good subsection"
when
$account : Account()
SubSection (status == "GOOD") from $account.getSubSections()
then
insertLogical(new AccountIsGood($account));
end
I would expect this to simply add the logical rule AccountIsGood($account)
if atleast one section was good. However, it seems this does not simply check for one successful subsection and end the rule, but instead it continues checking all subsections and inserting the logical rule for each valid subsection. Ex, if an account has four valid subsections, I get four copies of the rule for that account.
So my question is, is there a way to rewrite this rule to get the desired behavior?
The account class:
public class Account {
private List<SubSection> subsections;
// Getters / Setters/ other code
}
Account
which has a list ofSubSection
s. But, from your condition, looks like they are independent. Can you clarify? Can you also mention, if you are passing only theAccount
instance or theSubSection
s also to the engine? – Bhesh GurungkSession.execute(account);
. – Nixx