Example one-to-one
The following sections use the following business example.
Suppose the insurer had a regulatory requirement to have a set of activities periodically reviewed by the insurer's legal team. There are several fields needed to track this legal review, but they are applicable to only about 5% of all activities.
To improve database performance, the insurer opts to store this information in an
ActivityLegalInfo_Ext
entity and define it as a one-to-one with
Activity
.
- The
Activity
entity is the parent. Each activity can be associated with up to oneActivityLegalInfo_Ext
. ActivityLegalInfo_Ext
is the child. Each instance must be associated with exactly oneActivity
.
To implement this, the following has been added to the data model:
Activity
entityActivityLegalInfo_Ext
- one-to-one
- fkentity:
ActivityLegalInfo_Ext
- nullok: true
ActivityLegalInfo_Ext
entityLegalCaseNumber
- varchar with size 30
LegalReviewDate
- datetime
Activity
- foreign key
- fkentity:
Activity
- nullok: false
Note the following:
- On
Activity
, theActivityLegalInfo_Ext
field has nullok set to true. This is because someActivity
instances will have an associatedActivityLegalInfo_Ext,
but most will not. - On
ActivityLegalInfo_Ext
, theActivity
field has nullok set to false. This is because everyActivityLegalInfo_Ext
must be associated to anActivity
.
For a complete list of all code used to build this example, see Complete code sample for one-to-ones.