Return a new ``<Relationship>`` element.
189017
def new(cls, rId, reltype, target, target_mode=RTM.INTERNAL):
        
        xml = '<Relationship xmlns="%s"/>' % nsmap['pr']
        relationship = parse_xml(xml)
        relationship.rId = rId
        relationship.reltype = reltype
        relationship.target_ref = target
        relationship.targetMode = target_mode
        return relationship
1197502
def validate_relationship(self):
        """"""
        if self.relationship not in self._relationship_valid_values:
            raise ValueError("relationship should be one of: {valid}".format(
                valid=", ".join(self._relationship_valid_values)
            ))
457904
def new_pivot(self, attributes=None, exists=False):
        
        pivot = self._related.new_pivot(self._parent, attributes, self._table, exists)

        return pivot.set_pivot_keys(self._foreign_key, self._other_key)
603280
def encode_relation(relation: BioCRelation):
    """"""
    tree = etree.Element('relation', {'id': relation.id})
    encode_infons(tree, relation.infons)
    for node in relation.nodes:
        tree.append(encode_node(node))
    return tree
5714
public static Related asTargetBy(Relationships.WellKnown relationship) {
        return new Related(null, relationship.name(), EntityRole.TARGET);
    }
626087
protected function newQuery()
    {
        $query = $this->model->newQuery();

        foreach ($this->withRelationships as $relationship) {
            $query->with($relationship);
        }

        return $query;
    }
289037
def get_related_node(self, node, relation):
        """"""
        G = self.G
        for edge in G.edges(node):
            to = edge[1]

            to_relation = G.edges[node, to]['relation']
            if to_relation == relation:
                return to
        return None
193183
def addEdge(self, outVertex, inVertex, label):
        """"""
        n1 = outVertex.neoelement
        n2 = inVertex.neoelement
        edge = n1.relationships.create(label, n2)
        return Edge(edge)
874905
def relations_of_type(reltype=None):
    """"""
    relation_data = []
    reltype = reltype or relation_type()
    for relid in relation_ids(reltype):
        for relation in relations_for_id(relid):
            relation['__relid__'] = relid
            relation_data.append(relation)
    return relation_data
1244107
def get(self, *args, **kwargs):
        """"""
        self.before_get(args, kwargs)

        relationship_field, model_relationship_field, related_type_, related_id_field = self._get_relationship_data()

        obj, data = self._data_layer.get_relationship(model_relationship_field,
                                                      related_type_,
                                                      related_id_field,
                                                      kwargs)

        result = {'links': {'self': request.path,
                            'related': self.schema._declared_fields[relationship_field].get_related_url(obj)},
                  'data': data}

        qs = QSManager(request.args, self.schema)
        if qs.include:
            schema = compute_schema(self.schema, dict(), qs, qs.include)

            serialized_obj = schema.dump(obj)
            result['included'] = serialized_obj.data.get('included', dict())

        final_result = self.after_get(result)

        return final_result
71810
public function getToOneRelationship(string $relationship): ToOneRelationship
    {
        $data = $this->getResource();

        // The relationship has to exist in the request and have a data attribute to be valid
        if (isset($data["relationships"][$relationship]) && array_key_exists("data", $data["relationships"][$relationship])) {
            // If the data is null, this request is to clear the relationship, we return an empty relationship
            if ($data["relationships"][$relationship]["data"] === null) {
                return new ToOneRelationship();
            }
            // If the data is set and is not null, we create the relationship with a resource identifier from the request
            return new ToOneRelationship(
                ResourceIdentifier::fromArray($data["relationships"][$relationship]["data"], $this->exceptionFactory)
            );
        }

        throw $this->exceptionFactory->createRelationshipNotExistsException($relationship);
    }
562382
def handle_relations(changeset):
    """"""
    for relation in changeset.bundle.get('relations', []):
        relations = [models.Relation(*i.split(':')) if ':' in i
                     else models.Relation(i, '') for i in relation]
        changeset.send({
            'id': 'addRelation-{}'.format(changeset.next_action()),
            'method': 'addRelation',
            'args': [
                '${}'.format(
                    changeset.services_added[rel.name]) +
                (':{}'.format(rel.interface) if rel.interface else '')
                for rel in relations
            ],
            'requires': [changeset.services_added[rel.name] for
                         rel in relations],
        })
    return handle_units
847384
public void removeRelationshipsNotConnectedToElement(Element element) {
        if (element != null) {
            getRelationships().stream()
                    .map(RelationshipView::getRelationship)
                    .filter(r -> !r.getSource().equals(element) && !r.getDestination().equals(element))
                    .forEach(this::remove);
        }
    }
1258067
def candidate(cls):
        """"""
        return relationship(
            "Candidate",
            backref=backref(
                camel_to_under(cls.__name__) + "s",
                cascade="all, delete-orphan",
                cascade_backrefs=False,
            ),
            cascade_backrefs=False,
        )
103713
def create(self, validated_data):
        """"""
        # `partitions` field is renamed to `relationpartition_set` based on source of nested serializer
        partitions = validated_data.pop('relationpartition_set')

        with transaction.atomic():
            instance = Relation.objects.create(**validated_data)
            self._create_partitions(instance, partitions)

        return instance
705923
public void modifyRelationship(Relationship relationship, String description, String technology) {
        if (relationship == null) {
            throw new IllegalArgumentException("A relationship must be specified.");
        }

        Relationship newRelationship = new Relationship(relationship.getSource(), relationship.getDestination(), description, technology, relationship.getInteractionStyle());
        if (!relationship.getSource().has(newRelationship)) {
            relationship.setDescription(description);
            relationship.setTechnology(technology);
        } else {
            throw new IllegalArgumentException("This relationship exists already: " + newRelationship);
        }
    }
174955
def make_relationship(self, relator,
                          direction=
                            RELATIONSHIP_DIRECTIONS.BIDIRECTIONAL):
        
        if IEntity.providedBy(relator): # pylint:disable=E1101
            rel = DomainRelationship(relator, self,
                                     direction=direction)
        elif IResource.providedBy(relator): # pylint:disable=E1101
            rel = ResourceRelationship(relator, self,
                                       direction=direction)
        else:
            raise ValueError('Invalid relator argument "%s" for '
                             'relationship; must provide IEntity or '
                             'IResource.' % relator)
        return rel