summing child objects

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
Tom Morrison
Posts: 51
Joined: Wed Mar 29, 2006 12:48 pm
Location: Pennsylvania, USA
Contact:

summing child objects

Post by Tom Morrison »

OK....this is likely very simple, but I'm struggling.

I have a Registration object that includes an attribute named, TotalPaid. It's numeric and specified to be calculated. It also has a MyPayments attribute of the type Payment (child of Registration).

I have a Payment object that has an AmountPaid numeric attribute. There can be multiple Payment instances for a specific Registration.

I'd like to be able to sum up all of the Payment.AmountPaid for any particular Registration and have that number appear in Registration.TotalPaid.

Thought I had it working, but it seems to be summing ALL Payment instances, not just the ones associated with a specific Registration.

Thought I could do the following as a rule in Registration:
IF EXISTS Payment WHERE (Payment IN ThisRegistration.MyPayments)
Then TotalPaid = SUM (ThisRegistration.MyPayments.TotalPaid)
Else TotalPaid = 0

Obviously, I'm getting all Payment instances into Context.
aware_support2
Posts: 595
Joined: Sun Apr 24, 2005 2:22 am
Contact:

Post by aware_support2 »

Tom,

Your rule should look like this:

Registration.TotalPaid = SUM Payment.AmountPaid WHERE (Payment IN Registration.MyPayments)

You do not need the 'If' and 'Else' bits because the SUM will automatically return zero if there are no payments for the registration. Also, you do not need the 'This' prefix since there will be only once instance of Registration in the context when the rule is executed so the system will automatically recognize it.
Aware IM Support Team
Post Reply