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

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

Instance Method Summary collapse

Instance Method Details

#load_entity(neo_id) ⇒ Object?

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

Parameters:

  • neo_id (#to_i, nil)

Returns:

  • (Object, nil)

    If the node does not exist it will return nil otherwise the loaded relationship or wrapped relationship.

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

#new(type, from_node, to_node, *props) ⇒ Object 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

Parameters:

  • type (String, Symbol)

    the type of the relationships

  • from_node (Neo4j::Node, Neo4j::NodeMixin)

    create relationship from this node

  • to_node (Neo4j::Node, Neo4j::NodeMixin)

    create relationship to this node

  • props (Hash)

    optional hash of properties to initialize the create relationship with

See Also:



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