Skip to content
Kunihiko Ito edited this page Apr 8, 2016 · 4 revisions

Relationship

API

Neo4j::Relationship

Examples

How to create a relationship between node n1 and node n2 with one property

n1 = Neo4j::Node.create
n2 = Neo4j::Node.create
rel = n1.create_rel(:knows, n2, since: 1994)

# Alternative
Neo4j::Relationship.create(:knows, n1, n2, since: 1994)

Setting properties on relationships works like setting properties on nodes.

Finding relationships

# any type any direction any label
n1.rels

# Outgoing of one type:
n1.rels(dir: :outgoing, type: :know).to_a

# same but expects only one relationship
n1.rel(dir: :outgoing, type: :best_friend)

# several types
n1.rels(types: [:knows, :friend])

# label
n1.rels(label: :rich)

# matching several labels
n1.rels(labels: [:rich, :poor])

# outgoing between two nodes
n1.rels(dir: :outgoing, between: n2)

Returns nodes instead of relationships

# same parameters as rels method
n1.nodes(dir: :outgoing)
n1.node(dir: :outgoing)

Delete relationship

rel = n1.rel(:outgoing, :know) # expects only one relationship
rel.del

WARNING: Much of the information in this wiki is out of day. We are in the process of moving things to readthedocs

Api

Contribute

Clone this wiki locally