The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Neo4j::Types::Relationship - Represents a Neo4j relationship / graph edge

VERSION

version 2.00

SYNOPSIS

 $rel_type = $relationship->type;
 
 # Neo4j 5 and newer
 $rel_id        = $relationship->element_id;
 $start_node_id = $relationship->start_element_id;
 $end_node_id   = $relationship->end_element_id;
 
 # Neo4j 4 and older
 $rel_id        = $relationship->id;
 $start_node_id = $relationship->start_id;
 $end_node_id   = $relationship->end_id;
 
 $property1  = $relationship->get('property1');
 $property2  = $relationship->get('property2');
 %properties = %{ $relationship->properties };

DESCRIPTION

Describes a relationship from a Neo4j graph. A relationship may be created by executing a Cypher statement against a Neo4j database server. Its description contains the relationship's properties as well as certain meta data, all accessible by methods that this class provides.

Neo4j::Types::Relationship objects are typically not in a one-to-one relation with relationships in a Neo4j graph. If the same Neo4j relationship is fetched multiple times, then multiple distinct Neo4j::Types::Relationship objects may be created. Refer to the documentation of the Perl module you use to fetch relationships from the Neo4j database for information about how that particular module handles this aspect.

Neo4j relationship IDs are not designed to be persistent. As such, if you want a public identity to use for your relationships, attaching an explicit "id" property is a better choice than using the Neo4j relationship ID or element ID.

METHODS

Neo4j::Types::Relationship implements the following methods.

element_id

 $string = $relationship->element_id;

Return an ID string for this relationship that is unique within a particular context, for example the current transaction.

The element ID string was introduced with Neo4j 5. When it is unavailable, for example because this module is used with Neo4j server version 4 or earlier, this method will issue a warning in the Neo4j::Types category and return the legacy numeric ID instead; see id().

get

 $value = $relationship->get('property_key');

Retrieve the value of this relationship's property with the given key. If no such key exists, return undef.

id

 $number = $relationship->id;

Return a legacy numeric ID for this relationship that is unique within a particular context, for example the current transaction.

On Neo4j 5 and above, numeric IDs are deprecated. They may become unavailable in future. Use element_id() instead.

Legacy IDs are always integer numbers. A relationship with the ID 0 may exist. Nodes and relationships do not share the same ID space.

properties

 $hashref = $relationship->properties;
 $value   = $relationship->properties->{property_key};

Return all properties of this relationship as a hash reference.

This hash reference should be used for read access only. The result of attempts to change this hash is not defined by Neo4j::Types.

start_element_id

 $string = $relationship->start_element_id;

Return an element ID for the node where this relationship starts. See "element_id" in Neo4j::Types::Node.

start_id

 $number = $relationship->start_id;

Return a numeric ID for the node where this relationship starts. See "id" in Neo4j::Types::Node.

end_element_id

 $string = $relationship->end_element_id;

Return an element ID for the node where this relationship ends. See "element_id" in Neo4j::Types::Node.

end_id

 $number = $relationship->end_id;

Return a numeric ID for the node where this relationship ends. See "id" in Neo4j::Types::Node.

type

 $type = $relationship->type;

Return the type of this relationship.

SEE ALSO

AUTHOR

Arne Johannessen <ajnn@cpan.org>

If you contact me by email, please make sure you include the word "Perl" in your subject header to help beat the spam filters.

COPYRIGHT AND LICENSE

This software is Copyright (c) 2021-2023 by Arne Johannessen.

This is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0 or (at your option) the same terms as the Perl 5 programming language system itself.