Figure 9 ORM subschema for library loans.
Each loan is for exactly one book copy. The subset constraint between the loan-return and loan-end
associations declares that each loan that was returned on a date also ended on the same date. The
superscripts “2
” and “3
” on fact types indicate that a textual constraint applies to them. In this case, the
textual constraints are listed below the diagram. For each derived fact type (asterisked), a formal derivation
rule declares how instances of the fact type may be derived from other facts. This example includes four
derivation rules displayed below the diagram. ORM rules and queries (Bloesch and Halpin, 1997) may be
formally specified in relational style and/or attribute-style (using role names and/or defined functions). The
first derivation rule is expressed in relational style, the second rule in a combination of relational and
attribute styles, and the last two rules in attribute style. The derivation rule for unpaid fines determines the
fine currently accrued for an overdue loan—this amount may vary over time. The derivation rule for paid
fines enables the system to compute the fine amount actually paid. The predefined nrUnits function
converts a unit-based amount (e.g. 3 days) into a pure number (e.g. 3). This function may apply to any
expression that returns a unit-based type, and enhances semantic stability by protecting rules against
changes to choice of units.
Usually, constraints on derived fact types are themselves derivable. However, further constraints can
be explicitly added to them (e.g. the value constraint on NrOnLoanItems). This provides a convenient and
powerful way to declare various business rules that are awkward to express on base fact types.