Example one-to-one
The rest of the topics in this section 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
Activityentity is the parent. Each activity can be associated with up to oneActivityLegalInfo_Ext. ActivityLegalInfo_Extis the child. Each instance must be associated with exactly oneActivity.
To implement this, the following has been added to the data model:
ActivityentityActivityLegalInfo_Ext- one-to-one
- fkentity:
ActivityLegalInfo_Ext - nullok: true
ActivityLegalInfo_ExtentityLegalCaseNumber- varchar with size 30
LegalReviewDate- datetime
Activity- foreign key
- fkentity:
Activity - nullok: false
Note the following:
- On
Activity, theActivityLegalInfo_Extfield has nullok set to true. This is because someActivityinstances will have an associatedActivityLegalInfo_Ext,but most will not. - On
ActivityLegalInfo_Ext, theActivityfield has nullok set to false. This is because everyActivityLegalInfo_Extmust be associated to anActivity.
For a complete list of all code used to build this example, see Complete code sample for one-to-ones.