Module: Neo4j::Core::Relationship::ClassMethods

Included in:
Relationship
Defined in:
lib/neo4j-core/relationship/class_methods.rb

Instance Method Summary collapse

Instance Method Details

#_load(rel_id, db = Neo4j.started_db) ⇒ Object

Same as load but does not return the node as a wrapped Ruby object.

See Also:



46
47
48
49
50
51
52
53
# File 'lib/neo4j-core/relationship/class_methods.rb', line 46

def _load(rel_id, db = Neo4j.started_db)
  return nil if rel_id.nil?
  rel = db.graph.get_relationship_by_id(rel_id.to_i)
  # TODO
  rel
rescue Java::OrgNeo4jGraphdb::NotFoundException
  nil
end

#exist?(entity_or_entity_id, db = Neo4j.started_db) ⇒ true, false

Checks if the given node or entity id (Neo4j::Relationship#neo_id) exists in the database.

Returns:

  • (true, false)

    if exist



57
58
59
60
61
62
63
64
65
# File 'lib/neo4j-core/relationship/class_methods.rb', line 57

def exist?(entity_or_entity_id, db = Neo4j.started_db)
  id = entity_or_entity_id.kind_of?(Fixnum) ? entity_or_entity_id : entity_or_entity_id.id
  entity = _load(id, db)
  return false unless entity
  entity.hasProperty('_classname') # since we want a IllegalStateException which is otherwise not triggered
  true
rescue java.lang.IllegalStateException
  nil # the node has been deleted
end

#load(node_id, db = Neo4j.started_db) ⇒ Object?

Loads a relationship or wrapped relationship given a native java relationship or an id. If there is a Ruby wrapper for the relationship then it will create a Ruby object that will wrap the java node (see Neo4j::RelationshipMixin). To implement a wrapper you must implement a wrapper class method in the Neo4j::Node or Neo4j::Relationship.

Returns:

  • (Object, nil)

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



38
39
40
41
42
# File 'lib/neo4j-core/relationship/class_methods.rb', line 38

def load(rel_id, db = Neo4j.started_db)
  rel = _load(rel_id, db)
  return nil if rel.nil?
  rel.wrapper
end

#new(type, start_node, end_node, props = nil) ⇒ Neo4j::Relationship Also known as: create

Returns a Java::OrgNeo4jGraphdb::Relationship java object which include the Neo4j::Relationship mixins. Will trigger a event that the relationship was created.

Examples:


Neo4j::Relationship.new :friend, node1, node2, :since => '2001-01-02', :status => 'okey'

Parameters:

  • type (String, Symbol)

    of relationship

  • from_node (#_java_node)

    the start node of this relationship

  • end_node (#_java_node)

    the end node of this relationship

  • props (Hash) (defaults to: nil)

    optional properties for the created relationship

Returns:

  • (Neo4j::Relationship)

    which is really a Java::OrgNeo4jGraphdb::Relationship java object including the Neo4j::Relationship mixins



20
21
22
23
24
25
# File 'lib/neo4j-core/relationship/class_methods.rb', line 20

def new(type, start_node, end_node, props=nil)
  java_type = ToJava.type_to_java(type)
  rel = start_node._java_node.create_relationship_to(end_node._java_node, java_type)
  props.each_pair { |k, v| rel[k] = v } if props
  rel
end