In the EC object model a relationship class is a descendant of an ordinary class. It therefore has properties and can contain data. Hence an ECRelationship mapping is also a descendant of an ECClass mapping. Necessarily all operations previously described for the ECClass maping are possible for the relationship mapping too.
Natively a database maintains relationships via Foreign Keys. If the cardinality of relationship is defined 1 to many the Foreign Key is often a quite convenient way of storing such a relationships in a database.
Another case of cardinality is many to many. These are mostly stored in a separate table or tables and sometimes have their own properties.
Both types of relationships are supported by the Plant Project Database Mapping Extension.
Let's take a look at a mapping of a Foreign Key relationship. For example select the "EQUIPMENT_HAS_NOZZLE" relationship in the relationship class tree and click the "Edit" button or right click on the relationship class and select "Add Mapping..." from the context menu. The Edit relationship Mapping dialog box is displayed. This dialog box is very similar to the Edit Class Mapping dialog box but has one additional section "Relationship" that contains mappings for Keys of the Source and Target related classes. To create a mapping of a Foreign Key relationship it is necessary to perform the following steps:
In our example the Source constraint class is "EQUIPMENT" and the Target class is "NOZZLE". The ID of EQUIPMENT is in the Target's table. Thus it is necessary to define the "Source Key". Select "NOZZLE" as table and "NEQUIP" as column
Note: Only one of the mappings either for the Source Key or for the Target Key should be provided for the Foreign Key relationship.
Note: When a Foreign Key relationship mapping is created it is also optional possible to map ID, Name and Label and other properties similar to the Class Mapping. In practice such relationships are stored in a single field and even the InstanceID mapping cannot be provided. For such cases the InstanceID is auto-generated by the following rule:
<Source Instance ID>.<Target Instance ID>.<ECClass Name>
Note: The mapping of the Source Key and the Target Key allows involving two or more columns.
Note: The value of the Source and Target Key should be the same as the Instance ID of the Source or Target instances. E.g. the value of NOZZLE.NEQUIP_GUID_PK should be equal to the InstanceID of EQUIPMENT. Otherwise reading and writing of such a relationship won't work.
For relationships that are stored in a separate table everything that is possible for a class is possible as well. So all steps described in Creation of New Class Mapping should be done as well. Let's create a mapping for such a relationship e.g. for the "DOCUMENT_HAS_PIPELINE" relationship (see Fig.30):
⇒Next Plant Project Database - Property Mapping
⇐Back to Plant Project Database - Class Mapping
⇑Main OPPID - How to use the Class Editor Mapping Extension for the Plant Project Database