Defining a Relationship
Relationships are used to navigate. At a minimum, you need to know how to traverse relationships to get from one object to another. Furthermore, the repository engine supports complex behavior that varies based on relationships: namely, delete propagation, version propagation, view generation, version resolution, and naming relationships. To understand how the repository engine responds to these cases, you need to know about relationships and how they are structured.
Origin and Destination Collections
All relationships are accessed by way of a collection. For this reason, you must always associate objects through a relationship definition. When an origin object accesses a destination object, the origin object accesses a relationship collection that contains destination objects. When a destination object accesses an origin object, the destination object accesses a relationship collection that contains the origin object.
To support access in both directions, you must always provide two collections. From the perspective of the origin object, the relationship collection to which it is attached is a destination collection. Similarly, from the perspective of the destination object, the relationship collection to which it is attached is an origin collection.
When you define a relationship type and its attendant collection types, you must declare one collection type as the origin. To do this, you must set the IsOrigin property on the collection.
In addition to providing access, the distinction between origin and destination collections is important because naming collections, unique-naming collections, and sequenced collections can only be defined on origin collections.
The following example illustrates how to create an origin collection that supports unique-naming and sequencing. In this example, objid_null is the object identifier, name_ is the string that defines a name, and dispid_ indicates a dispatch identifier (a constant not shown in this example).
Rem ** Declare interface, collection, and relationship
Dim oTypeLib as RepositoryTypeLib
Dim oRContains as RelationshipDef
Dim oCTableContains as CollectionDef
Rem ** Create the oRContains relationship on oTypeLib
Set oRContains = oTypeLib.CreateRelationshipDef(objid_null, name_Contains)
Rem ** Create the relationship collection for oRContains
Rem ** IsOrigin is set to True
Rem ** 10 is the combined bits for CollectionDef flags (2 for uniquenaming, 8 for sequenced)
Set oCTableContains = oTypeLib.CreateRelationshipColDef(objid_null, name_CTableContains, dispid_TableContains, True, 10, oRContains)
See Also
CollectionDef IsOrigin Property
Defining Relationships and Collections