Hi Michael,

To do the opposite approach (where the relationship is navigable from the
parent only) you can use the following:

when
       c : Child ( age > 18 )
       Parent ( children contains c, type == "SMURF" )

Of course this requires either

  - the child object in the children collection to be the same as the
  asserted child object or
  - the equals/hashcode method to be implemented appropriately in Child

cheers
Steve

On 1/24/07, Anstis, Michael (M.) <[EMAIL PROTECTED]> wrote:

 Sorry, me again,

I'm putting together some prototype rules that operate on related objects
in a graph of objects.

I'm adding all objects individually to working memory and then checking
the objects are related in the rule to ensure only valid combinations are
selected; for example:-

//Java code
parent.addChild(child)
wm.assertObject(parent);
wm.assertObject(child);

//Rule
rule "Adult smurfs"
when
        c : Child ( age > 18, p : parent )
        Parent ( parentId == ( p.parentId ), type == "SMURF" )
then
        System.out.println("Smurf " + p.getName() + " is " + c.getAge() +
" years old."
end

rule "Adult clangers"
when
        c : Child ( age > 18, p : parent )
        Parent ( parentId == ( p.parentId ), type == "CLANGER" )
then
        System.out.println("Clanger " + p.getName() + " is " + c.getAge()
+ " years old."
end

This requires that the parent-child relationship is navigable from the
child end of the relationship -- child.getParent().

What other approaches does anyone else use to implement rules that span
related objects?

With kind regards,

Michael Anstis
-------------------------------------------
***Next Generation Estimating System*
( Trafford House (Int) 8 718 2239
( Trafford House (Ext) +44 (0)1268 702239
* <***mailto:[EMAIL PROTECTED] <[EMAIL PROTECTED]>>

_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users





--
Steven Williams

Supervising Consultant

Object Consulting
Office: 8615 4500 Mob: 0439 898 668 Fax: 8615 4501
[EMAIL PROTECTED]
www.objectconsulting.com.au

consulting | development | training | support
our experience makes the difference
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

Reply via email to