Count Rule Type

Count Rule Type
lac32
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 as 
count
(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_count
 in 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.
API Creator makes 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, count values are assumed 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
  1. In API Creator, select Manage, Rules, and click the
    Create New Rule
    .
  2. Select the Count rule type, the entity to which it applies, and click
    Create Rule
    .
  3. Define the parameters of the rule:
    Count name
    The name of the count rule.
     
    To apply a default value, leave this field blank.
     
    Entity/column
    The name of the parent entity and column representing the count result.
    Topics
    The topic associated with this rule.
    Children
    Defines the child role and the attribute that is being counted.
    For more information about roles and foreign key-based relationships, see Data Sources.
    Qualification
    Boolean JavaScript expression designating the child rows that contribute to the count.
    Syntax notes: 
    Use logical operators such as && for "and", || for "or." You can specify equals either as "=", or "==."
     
    Optional: 
    Yes
    Active
    Select this checkbox to activate the rule.
     
    The API must be complete.
     
    SQLable
    Indicates whether you can optimize the rule by executing it in SQL instead of in JavaScript.
    Just In Time
    Select to specify that 
    CA Live API Creator
     recompute the data values.
    If the value in the database is null, 
    CA Live API Creator
     executes the rule on the first read, stores the value for that column in the database, and returns the value. To prevent 
    CA Live API Creator
     from executing rules with null return values on every read, the rule should never return a null value.
     
    Specifying count rules as Just in Time (JIT) can affect performance whenever new values are computed on the fly.
    For more information about JIT, including how to specify to have 
    CA Live API Creator
     recompute your rules when/as it detects null vales, see Synchronize Data with Logic.
  4. Click
    Activate and Close
    to return to the list of rules.
The count rule is created.