Module: Neo4j::Wrapper::RelationshipMixin::ClassMethods

Defined in:
lib/neo4j-wrapper/relationship_mixin/class_methods.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object?) load_entity(neo_id)

Loads a wrapped relationship from the database given a neo id.

Raises:

  • an exception if the loaded node/relationship is not of the same kind as this class.



32
33
34
35
36
37
38
# File 'lib/neo4j-wrapper/relationship_mixin/class_methods.rb', line 32

def load_entity(neo_id)
  node = Neo4j::Relationship.load(neo_id)
  return nil if node.nil?
  return node if node.class == Neo4j::Relationship
  raise "Expected loaded node #{neo_id} to be of type #{self} but it was #{node.class}" unless node.kind_of?(self)
  node
end

- (Object) new(type, from_node, to_node, *props) Also known as: create

Creates a relationship between given nodes.

You can use two callback method to initialize the relationship

init_on_load

this method is called when the relationship is loaded from the database

init_on_create

called when the relationship is created, will be provided with the same argument as the new method



17
18
19
20
21
22
23
24
# File 'lib/neo4j-wrapper/relationship_mixin/class_methods.rb', line 17

def new(type, from_node, to_node, *props)
  rel = Neo4j::Relationship.create(type, from_node, to_node)
  wrapped_rel = super()
  Neo4j::IdentityMap.add(rel, wrapped_rel)
  wrapped_rel.init_on_load(rel)
  wrapped_rel.init_on_create(type, from_node, to_node, *props)
  wrapped_rel
end