Sum Rule Type
Sum Rule Type
Sum rules are derivation rules that declare a parent attribute to be maintained as the sum of a designated child role's summed attribute, with an optional qualification to filter child objects. Parent reference names are derived from foreign key relationships.
For example, to derive the balance as the sum of the unpaid order totals:
Derive balance assum(purchaseorderList.amount_total where paid=false)
Use sum rules instead of events. The impact on performance is small. Adjustment is by way of one-row updates instead of expensive aggregate SQLs, like
CA Live API Creatorupdates the value of the attribute to reflect the sum of the specified attribute in the child objects whenever necessary. This includes adding and removing child objects from the parent object, as well as modifications to the children objects that change their qualification in the sum or the summed value. Sum processing is triggered by changes to the child. For example, when you add a new (qualifying) child to the parent,
CA Live API Creatorincrements the sum attribute by the child's amount.
You can view the changes in the log.
Best Practice:To maintain high performance, sum values are assumed to be correct on disk. For proper operation, if you define new sums on existing data, initialize these using SQL tools.
For more information:
Create a Sum Rule
Prerequisite:You have defined an active database with at least one table or view.
- In API Creator, in the Manage section, clickRules.If your API does not have existing rules, the Welcome to Rules page appears. If your API has existing rules, they are listed on the By entity tab by default.
- Complete one of the following:
- If you have not defined any rules, on the Welcome to Rules page, clickCreate a Rule.
- If you have at least one rule defined, on the By entity tab, clickCreate New Rule.
- Select theSumrule type, the entity to which it applies, and then clickCreate Rule.
- Use logical operators such as && for "and", || for "or".
- Specify equals as "=" or "==".
- Specify not equals as !=.
- Use the attrName, not row.<attrName>.
- ClickActivate and Closeto return to the list of rules.
The sum rule is created.