Class: Neo4j::Relationship

Inherits:
Object
  • Object
show all
Includes:
EntityEquality, PropertyContainer, Wrapper
Defined in:
lib/neo4j/relationship.rb

Overview

A relationship between two nodes in the graph. A relationship has a start node, an end node and a type. You can attach properties to relationships like Neo4j::Node.

The fact that the relationship API gives meaning to start and end nodes implicitly means that all relationships have a direction. In the example above, rel would be directed from node to otherNode. A relationship's start node and end node and their relation to outgoing and incoming are defined so that the assertions in the following code are true:

Furthermore, Neo4j guarantees that a relationship is never “hanging freely,” i.e. start_node, end_node and other_node are guaranteed to always return valid, non-nil nodes.

Direct Known Subclasses

Server::CypherRelationship

Defined Under Namespace

Modules: Wrapper

Constant Summary

Constant Summary

Constants included from PropertyValidator

PropertyValidator::VALID_PROPERTY_VALUE_CLASSES

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Wrapper

#neo4j_obj, #wrapper

Methods included from EntityEquality

#==

Methods included from PropertyContainer

#[], #[]=

Methods included from PropertyValidator

#valid_property?, #validate_property

Class Method Details

+ (Object) create(rel_type, from_node, other_node, props = {})



150
151
152
# File 'lib/neo4j/relationship.rb', line 150

def create(rel_type, from_node, other_node, props = {})
  from_node.neo4j_obj.create_rel(rel_type, other_node, props)
end

+ (Object) load(neo_id, session = Neo4j::Session.current)



154
155
156
# File 'lib/neo4j/relationship.rb', line 154

def load(neo_id, session = Neo4j::Session.current)
  session.load_relationship(neo_id)
end

Instance Method Details

- (Neo4j::Node) _end_node

Same as #end_node but does not wrap the node



86
87
88
# File 'lib/neo4j/relationship.rb', line 86

def _end_node
  raise 'not implemented'
end

- (Object) _other_node(node)

Same as #other_node but can return a none wrapped node



136
137
138
139
140
141
142
143
144
145
146
# File 'lib/neo4j/relationship.rb', line 136

def _other_node(node)
  s = _start_node
  e = _end_node
  if node == _start_node
    return _end_node
  elsif node == _end_node
    return _start_node
  else
    raise "Node #{node.inspect} is neither start nor end node"
  end
end

- (Neo4j::Node) _start_node

Same as #start_node but does not wrap the node



74
75
76
# File 'lib/neo4j/relationship.rb', line 74

def _start_node
  raise 'not implemented'
end

- (Object) del

This method is abstract.


91
92
93
# File 'lib/neo4j/relationship.rb', line 91

def del
  raise 'not implemented'
end

- (Neo4j::Node, Object) end_node

Returns the end node of this relationship.



80
81
82
# File 'lib/neo4j/relationship.rb', line 80

def end_node
  _end_node.wrapper
end

- (true, false) exist?

This method is abstract.

Returns if the relationship exists



103
104
105
# File 'lib/neo4j/relationship.rb', line 103

def exist?
  raise 'not implemented'
end

- (Object) get_property(key, value)

Directly get the property on the relationship (low level method, may need transaction)



62
63
64
# File 'lib/neo4j/relationship.rb', line 62

def get_property(key, value)
  raise 'not implemented'
end

- (Object) neo_id

This method is abstract.

The unique neo4j id



97
98
99
# File 'lib/neo4j/relationship.rb', line 97

def neo_id
  raise 'not implemented'
end

- (Neo4j::Node) other_node(node)

A convenience operation that, given a node that is attached to this relationship, returns the other node. For example if node is a start node, the end node will be returned, and vice versa. This is a very convenient operation when you're manually traversing the node space by invoking one of the #rels method on a node. For example, to get the node “at the other end” of a relationship, use the following:

Examples:

end_node = node.rels.first.other_node(node)

Raises:

  • This operation will throw a runtime exception if node is neither this relationship's start node nor its end node.

See Also:



131
132
133
# File 'lib/neo4j/relationship.rb', line 131

def other_node(node)
  _other_node(node.neo4j_obj).wrapper
end

- (Hash<Symbol,Object>) props



31
32
33
# File 'lib/neo4j/relationship.rb', line 31

def props()
  raise 'not implemented'
end

- (Object) props=(properties)

replace all properties with new properties



37
38
39
# File 'lib/neo4j/relationship.rb', line 37

def props=(properties)
  raise 'not implemented'
end

- (Symbol) rel_type

Returns the relationship name

Examples:

a = Neo4j::Node.new
a.create_rel(:friends, node_b)
a.rels.first.rel_type # => :friends


114
115
116
# File 'lib/neo4j/relationship.rb', line 114

def rel_type
  raise 'not implemented'
end

- (Object) remove_property(key)

Directly remove the property on the relationship (low level method, may need transaction)



48
49
50
# File 'lib/neo4j/relationship.rb', line 48

def remove_property(key)
  raise 'not implemented'
end

- (Object) set_property(key, value)

Directly set the property on the relationship (low level method, may need transaction)



55
56
57
# File 'lib/neo4j/relationship.rb', line 55

def set_property(key, value)
  raise 'not implemented'
end

- (Neo4j::Node, Object) start_node

Returns the start node of this relationship.



68
69
70
# File 'lib/neo4j/relationship.rb', line 68

def start_node
  _start_node.wrapper
end

- (Object) update_props(properties)

Updates the properties, keeps old properties



43
44
45
# File 'lib/neo4j/relationship.rb', line 43

def update_props(properties)
  raise 'not implemented'
end