## Open '''A''' in the Relation Editor. In the tree view you see now, drag '''B''' onto the tree node for the previously created relation.
# Save all changes. The connection is now established and can be used, e.g., in the ACM view or by programmatic customizing.
== Connecting objects by customizing code ==
=== Reference ===
You can set a reference connection by custom code as follows, assuming you have:
* A meta class with a reference meta property
* An instance "objectA" of that meta class
* An instance "objectB" of the reference target meta class
<source lang="csharp">
// Setting a reference using the property name
string referencePropertyName = "LNK_MY_REFERENCE_PROPERTY";
objectA.SetLinkedObject(referencePropertyName, objectB);
// You can also remove the connection by setting it to null
objectA.SetLinkedObject(referencePropertyName, null);
</source>
Similarly, you can also read a connected object:
<source lang="csharp">
string referencePropertyName = "LNK_MY_REFERENCE_PROPERTY";
BaseClass objectB = objectA.GetLinkedObject(referencePropertyName);
// You can also get the objects referring to objectB, restricted by their metaclass.
MetaClass someMetaClass = objectA.MetaClass;
objectB.ReferencedByObjects(someMetaClass);
</source>
=== Relation ===
You can add a relational connection by custom code as follows, assuming you have:
* A relation
* An instance "objectA" of the relation's left target meta class
* An instance "objectB" of the relation's right target meta class
<source lang="csharp">
Relationship relation = objectA.Environment.UBIKDataFactory().Relation(Guid.Parse("insert UID of relation here"));
// You can, alternatively, get the relation by name instead of UID:
objectA.TryGetRelationByName("insert name of relation", out relation);
// Adding a relational connection
((RelationalObject)objectA).AddRelation(relation, objectB);
// Removing a relational connection
((RelationalObject)objectA).RemoveRelation(relation, objectB);
</source>
You can also read relational information in multiple ways (assuming objectA is already declared as variable of type RelationalObject to avoid the casts):
<source lang="csharp">
Relationship relation = objectA.Environment.UBIKDataFactory().Relation(Guid.Parse("insert UID of relation here"));
// You can, alternatively, also get the relation by name instead of UID:
objectA.TryGetRelationByName("insert name of relation", out relation);
// Getting all objects related to objectA (children of objectA)
UBIKClassList<RelationalObject> childrenOfA = objectA.RelatesTo(relation);
// Getting all objects reverse-related to objectB (parents of objectB)
UBIKClassList<RelationalObject> parentsOfB = objectB.RelatesFrom(relation);
</source>
[[Category:How-To|Relate Objects]]