Add a relationship between this object and another object.

def add_relation(self,
                     target_id=None,
                     relation_types=None,
                     fact_dt_namespace_name=None,
                     fact_dt_namespace_uri=DINGOS_NAMESPACE_URI,
                     fact_dt_kind=FactDataType.UNKNOWN_KIND,
                     fact_dt_name='String',
                     metadata_dict=None,
                     markings=None
    ):
        """
        Add a relationship between this object and another object.
        """
        if not markings:
            markings = []

        if relation_types == None:
            relation_types = []

        # Create fact-term for relation types
        relation_type_ft, created = get_or_create_fact_term(iobject_family_name=self.iobject_family.name,
                                                            fact_term_name=DINGOS_RELATION_TYPE_FACTTERM_NAME,
                                                            iobject_type_name=self.iobject_type.name,
                                                            iobject_type_namespace_uri=self.iobject_type.namespace.uri,
                                                            fact_dt_name=fact_dt_name,
                                                            fact_dt_namespace_name=fact_dt_namespace_name,
                                                            fact_dt_kind=fact_dt_kind,
                                                            fact_dt_namespace_uri=fact_dt_namespace_uri)

        # Create fact containing relation types
        relation_type_fact, created = get_or_create_fact(fact_term=relation_type_ft,
                                                         fact_dt_name=fact_dt_name,
                                                         fact_dt_namespace_uri=fact_dt_namespace_uri,
                                                         values=relation_types,
                                                         value_iobject_id=None,
                                                         value_iobject_ts=None,
                                                         )

        rel_target_id = target_id
        rel_source_id = self.identifier

        # Create relation object
        relation, created = self._DCM['Relation'].objects.get_or_create(
            source_id=rel_source_id,
            target_id=rel_target_id,
            relation_type=relation_type_fact)

        # Add markings
        for marking in markings:
            Marking2X.objects.create(marked=relation,
                                     marking=marking)

        if metadata_dict:
            # If the relation already existed and had associated metadata,
            # we retrieve the identifier of that metadata object and
            # write the current metadata as new revision. Otherwise,
            # we create a new identifier.

            if relation.metadata_id:
                rel_identifier_uid = relation.metadata_id.uid
                rel_identifier_namespace_uri = relation.metadata_id.namespace.uri
            else:
                rel_identifier_uid = None
                rel_identifier_namespace_uri = DINGOS_ID_NAMESPACE_URI

            metadata_iobject, created = get_or_create_iobject(identifier_uid=rel_identifier_uid,
                                                              identifier_namespace_uri=rel_identifier_namespace_uri,
                                                              iobject_type_name=DINGOS_RELATION_METADATA_OBJECT_TYPE_NAME,
                                                              iobject_type_namespace_uri=DINGOS_NAMESPACE_URI,
                                                              iobject_type_revision_name=DINGOS_REVISION_NAME,
                                                              iobject_family_name=DINGOS_IOBJECT_FAMILY_NAME,
                                                              iobject_family_revision_name=DINGOS_REVISION_NAME,
                                                              timestamp=None,
                                                              overwrite=False)
            metadata_iobject.from_dict(metadata_dict)

        return relation