Refer to Entities Connected by a To-Many Relationship
Anytime you refer from one entity to another entity in a "to-many" relationship, you need to indicate whether one or all members of the target entity group need to satisfy the rule.
Consider the following rule:
A family may board the plane first if their child is under 8 years of age
We know that families can have more than one child, however, this rule does not specify whether one or all of the family's children must be under 8 years of age in order for the family to board the plane first. If the family had two children, one aged 4 and one aged 16, how would you decide?
The rule would be clearer if written in such a way that the reader can tell whether the rule applies to one or all children. For example:
A family may board the plane first if they have at least one child under 8 years of age
We use the ForAll and Exists functions to write these kinds of rules. That is:
- the ForAll function is used to check that the condition returns true for every instance of an entity. For example, "All of the apples are red".
- the Exists function is used to check that the condition returns true for at least one instance of an entity. For example, "At least one of the bananas is yellow".