The goal of this example is to create a foreign key between attributes of two IBM® Content Manager item types and to demonstrate that the foreign key constraint is used as expected in the IBM Content Manager clients.
A system administrator who is responsible for the data modeling for the business creates attributes, item types that use these attributes, and a foreign key that links between the attributes to provide referential integrity across items created with the item types. The process flow for these tasks includes the following steps:
Create the attributes: Create two attributes, a FormId attribute to hold the identifier (ID) for a type of form, and a FormName attribute to hold the text description of the form type.
Create the first item type: Create a FormType item type to contain the form types that will be added as items. Add the FormId attribute to the item type to store the IDs of form types. Add the FormName attribute to the item type to store the descriptions of form types. Prepare the FormId attribute to be used as part of the foreign key. Set the FormId to be a required attribute for the FormType item so that each form type has an ID. Set the FormId to be a unique attribute for the FormType so that each ID is unique.
Create the foreign key on the second item type: As part of the creation of the Forms item type, create a foreign key constraint with the Forms item type as the source item type and the FormType item type as the target item type. Set the FormId attribute as the source attribute and target attribute. In the foreign key relationship, the source is constrained by the target. Therefore, the values available to the FormId attribute in the Forms item type are limited by the values available in the FormId attribute in the FormType item type.
A business analyst who is responsible for creating the objects for the business creates the form types in the FormType item type. This action includes assigning IDs to the form types by using the FormId attribute. The business analyst creates two new form items with the FormFolder item type, a medical insurance application with the form ID 1A100001 and a medical claim form with the form ID 1A100002. The process flow for these tasks includes the following steps:
Users who are responsible for importing the forms into the content management system work with forms according to the normal business process, such as importing scanned documents. When a user imports a form, the user assigns an ID that defines the type of form that is imported. The client that is used to import the document limits the values for the ID by using the foreign key constraint. The client might limit the values directly in the interface by using the acceptable values in a drop-down menu, or the client might limit the values indirectly by verifying the supplied value on the library server.
For example, a user imports a form with their web client. The web client can display the IBM Content Manager foreign key item types and attributes in the interface. Therefore, the user can select Forms from the Item type field and select an ID from a FormId drop-down list. The FormId list contains only the IDs entered by the business analyst as the FormId values for the FormType item type.
Other client applications might not display the foreign key values for selection. For example, the Client for Windows does not display the values from foreign keys by default. In addition, a custom client application might not be designed to show these values. However, regardless of the client that is used, the foreign key referential integrity is enforced by the library server.
For example, a user imports a form with the Client for Windows, using the Forms item type. Because a FormId drop-down list does not display in the Client for Windows, the user enters an ID value manually. The ID contains a typographical error, such as 1AA00001 when the valid IDs are 1A100001 and 1A100002. The resulting entry is not defined as a FormId in the FormType item type. When the user imports the form, the following error message is shown: The system could not create a document object. The error details contain IBM Content Manager and SQL error codes to help the user work with the system administrator. The error codes show that the value for the dependent table (the FormId attribute of the Forms item type) does not match any value of the parent key in the parent table (the FormId attribute of the FormType item type).
In this example, attributes and item types were created in IBM Content Manager. A foreign key relationship was created between two item types. An attribute that was used in both item types was configured as a foreign key to constrain the values of the attribute from one item type to another. The values were displayed in the web client interface to limit the values that users could select when creating items. In addition, other client applications that could not display the values still used the foreign key to enforce referential integrity between the two item types.