Yes thats allowed, and this, if you have a parent field.
p : CompositeNode( name == "Parent" )
c : CompositeNode(parent == p)
Russ Egan wrote:
How about this:
when
c : CompositeNode()
p : CompositeNode(name == "Parent", child == c)
then...
On Fri, 21 Apr 2006 11:24:35 -0400, Mitch Christensen
<[EMAIL PROTECTED]> wrote:
Hey,
Quite often I want to process related facts. For example, I have a
CompositeNode fact in working memory that references another
CompositeNode
fact. In such cases I want to be able to process all composites and
their
associated components (i.e. children) in a rule.
The following code snippet demonstrates,
rule "Add related (and a few unrelated) facts"
when
not CompositeNode( name == "Parent" )
then
CompositeNode parent = new CompositeNode("Parent", new
CompositeNode("Child"));
assert(parent);
assert(parent.getChild());
assert(new CompositeNode("RandomNode1"));
assert(new CompositeNode("RandomNode2"));
end
rule "Test related facts"
when
p : CompositeNode( name == "Parent", c : child )
c : CompositeNode()
then
System.out.println("p.name: " + p.getName() + " references
c.name: " + c.getName() + "\n");
end
The first rule asserts a parent node with an associated child node, then
asserts the associated child node and then two random (i.e.
unassociated)
nodes. The second rule attempts to process each parent-child
relationship.
Because Drools doesn't recognize fact bindings across conditions, my
second
rule erroneously processes the cross-join of CompositeNode objects.
What I want to do is roughly equivalent to an SQL join using the 'child'
property as foreign key. Something like SELECT * FROM CompositeNode
WHERE
child = id. This is a very important feature of Jess that I used
regularly.
Is there a way to do this in drools that I just don't see?
Thanks.
-Mitch
--Using Opera's revolutionary e-mail client: http://www.opera.com/mail/