Count Rule Type
Count Rule Type
Count rules are derivation rules that calculate the number of child objects, with an optional child qualification condition (where clause). API Creator derives the parent attribute value by counting designated child rows. You can 'trigger' an event action using the state change (increase or decrease) in a child row. For example, if the count of the child transactions is greater than 100, you could archive the older rows to MongoDB.
The count rule declares an attribute to be maintained as the count of a designated child role, with an optional qualification to filter child objects. For example:
Derive orders.item_count ascount(lineitemsList)
Count rules are useful as chid existence checks. For example, you can ensure that orders have at least one line item entry using the
item_countin a (commit!) validation. When necessary, API Creator updates the value of the attribute to reflect the count of the specified attribute in the child objects. This includes the child objects you add to and remove from the parent object, as well as modifications to the child objects that change their qualification in the count. Changes to the child triggers count processing. You can view the changes in the log.
CA Live API Creatormakes adjustments to recalculate the count. For instance, when you add a new (qualifying) child to the parent, the count attribute is incremented by one. The performance impact is small.
Best Practice:To maintain high performance,
CA Live API Creatorassumes count values to be correct on disk. For proper operation, if you define new counts on existing data, bring your current schema into conformance by initializing those new counts using SQL tools.
For more information:
Create Count Rules
Prerequisite:Your API is connected to an active database that contains 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.
- ClickCreate a Rule.
- Select theCountrule type, the entity to which it applies, and then clickCreate Rule.
- ClickActivate and Closeto return to the list of rules.
The count rule is created.