Relate Objects
Relating objects is one of the essential parts within UBIK® and can be achieved by two means:
- Use Relations to build up an n:n relationship between two instances of an entity
- Use References to build up an 1:n relationship between two instances of an entity
Which method fits best depends on the use case and the data model.
Connect objects via Reference
If you want one or multiple objects to refer to a single target object each, a reference is what you need. You can either ask an object about the one it refers to, or ask a target object about all objects referring to it via a reference. This is useful, if you want to connect objects but there is no necessity for both "sides" to be connected to multiple other objects.
In this case, an object's property contains a link to the target object (respectively, its UID). Let's call the target object B and the object referring to the target object A. A refers to B.
In order to achieve this, the following requirements must be met:
- The MetaClass of object A must have a respectively configured link MetaProperty.
- The property type should be Guid. - A Reference object defining the target MetaClass should be set on the MetaProperty.
- The property value for the link MetaProperty on object A must be set to object B.
You can achieve this with the following steps:
- Create a new Reference (Create a new Reference).
- Set the MetaClass of B on the TARGETTYPE property of the previously created reference, as explained in the HowTo above.
- Make sure there is a MetaProperty on the MetaClass of object A you can use. If necessary, create a new MetaProperty instance and relate it to the MetaClass of A via the MetaClass to MetaProperty relation (Add a MetaProperty to a MetaClass).
- Set the previously created reference on the new MetaProperty (Create a new MetaProperty).
- Make sure all changes are saved.
- Open the Bulk Editor for the MetaClass of A and set the property value for the new MetaProperty on A to B, in one of the following ways:
** dragging and dropping object B onto the cell ** selecting the object B from the dialog appearing after double-clicking the cell
- Save object A. The connection is now established and can be used, e.g., in the ACM view or by programmatic customizing.