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::Driver::Type::Relationship - Describes a relationship from a Neo4j graph

VERSION

version 0.14

SYNOPSIS

 my $q = "MATCH (a:Person)-[k:KNOWS]->(b:Person) RETURN k";
 my $rel = $driver->session->run($q)->list->[0]->get('k');
 
 print 'Person # ', $rel->start_id;
 print ' ', $rel->type;
 print ' person # ', $rel->end_id;
 print ' since ', $rel->properties->{since};

DESCRIPTION

Describes a relationship from a Neo4j graph. A relationship may be a part of records returned from Cypher statement execution. Its description contains the relationship's properties as well as certain meta data, all accessible by methods that this class provides.

Neo4j::Driver::Type::Relationship objects are 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::Driver::Type::Relationship objects will be created by the driver. If your intention is to verify that two Neo4j::Driver::Type::Relationship objects in Perl describe the same node in the Neo4j database, you need to compare their IDs.

METHODS

Neo4j::Driver::Type::Relationship implements the following methods.

get

 my $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

 my $id = $relationship->id;

Return a unique ID for this relationship.

In the Neo4j Driver API, entity IDs are only guaranteed to remain stable for the duration of the current session. Although in practice server versions at least up to and including Neo4j 3.5 may appear to use persistent IDs, your code should not depend upon that.

A relationship with the ID 0 may exist. Nodes and relationships do not share the same ID space.

properties

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

Return all properties of this relationship as a hash reference.

start_id

 my $id = $relationship->start_id;

Return the ID of the node where this relationship starts.

end_id

 my $id = $relationship->end_id;

Return the ID of the node where this relationship ends.

type

 my $type = $relationship->type;

Return the type of this relationship.

EXPERIMENTAL FEATURES

Neo4j::Driver::Type::Relationship implements the following experimental features. These are subject to unannounced modification or removal in future versions. Expect your code to break if you depend upon these features.

Direct data structure access

 my $property_value = $relationship->{property_key};

Currently, the relationship's properties may be directly accessed as if the relationship was a simple hashref. This is a concession to backwards compatibility, as the data structure only started being blessed as an object in version 0.13.

Relying on this implementation detail is not deprecated. Use the accessor methods get() and properties() instead.

Deletion indicator

 my $node_exists = ! $relationship->deleted;

In some circumstances, Cypher statements using DELETE may still RETURN relationships that were deleted. To help avoid confusion in such cases, the server sometimes reports whether or not a relationship was deleted.

This method is experimental because that information is not reliably available. In particular, there is a known issue with the Neo4j server (#12306), and old Neo4j versions may not report it at all. If unavailable, undef will be returned by this method.

BUGS

The value of properties named _meta, _relationship, _start, _end, or _type may not be returned correctly.

When using HTTP, the type of relationships that are returned as part of a Neo4j::Driver::Type::Path is unavailable, because that information is not currently reported by the Neo4j server. undef is returned instead.

SEE ALSO

Neo4j::Driver, Neo4j Java Driver, Neo4j Python Driver

AUTHOR

Arne Johannessen <ajnn@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2016-2019 by Arne Johannessen.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)