Class: Neo4j::Relationship

Inherits:
Object
  • Object
show all
Extended by:
Core::Index::ClassMethods, Core::Relationship::ClassMethods, Core::Wrapper::ClassMethods
Includes:
Core::Equal, Core::Index, Core::Property, Core::Property::Java, Core::Relationship, Core::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.

Wrapping

Notice that the Neo4j::Relationship.new does not create a Ruby object. Instead, it returns a Java Java::OrgNeo4jGraphdb::Relationship object which has been modified to feel more rubyish (like Neo4j::Node).

Examples:

a = Neo4j::Node.new
b = Neo4j::Node.new
rel = Neo4j::Relationship.new(:friends, a, b)
# Now we have: (a) --- friends ---> (b)

rel.start_node # => a
rel.end_node   # => b

using the << operator on the Neo4j::Node relationship methods


node.outgoing(:friends) << other_node << yet_another_node

lucene index

Neo4j::Relationship.trigger_on(:typey => 123)
Neo4j::Relationship.index(:name)
a = Neo4j::Relationship.new(:friends, Neo4j::Node.new, Neo4j::Node.new, :typey => 123, :name => 'kalle')
# Finish tx
Neo4j::Relationship.find(:name => 'kalle').first.should be_nil

See Also:

Instance Attribute Summary

Attributes included from Core::Index::ClassMethods

#_indexer

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Core::Relationship::ClassMethods

_load, exist?, load, new

Methods included from Core::Wrapper::ClassMethods

wrapper, wrapper_proc=

Methods included from Core::Index::ClassMethods

_config, add_index, find, has_index_type?, index, index?, index_for_type, index_name_for_type, index_type, indexer, node_indexer, put_if_absent, rel_indexer, rm_index, rm_index_config, rm_index_type, trigger_on

Methods included from Core::Index

#add_index, #rm_index

Methods included from Core::Property::Java

#get_property, #graph_database, #property_keys, #remove_property, #set_property

Methods included from Core::Wrapper

#_java_entity, #wrapper

Methods included from Core::Relationship

#_end_node, #_java_entity, #_java_rel, #_other_node, #_start_node, #class, #del, #end_node, #exist?, #other_node, #rel_type, #start_node

Methods included from Core::Equal

#==, #eql?, #equal?

Methods included from Core::Property

#[], #[]=, #neo_id, #property?, #props, #update

Constructor Details

#initialize(rel_type, start_node, end_node, props = {}) ⇒ Neo4j::Relationship

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: {})

    optional properties for the created relationship



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

def initialize(rel_type, start_node, end_node, props={})
end

Class Method Details

.extend_java_class(java_clazz) ⇒ Object

:nodoc:



64
65
66
67
68
69
70
71
72
# File 'lib/neo4j/relationship.rb', line 64

def extend_java_class(java_clazz) #:nodoc:
  java_clazz.class_eval do
    include Neo4j::Core::Property
    include Neo4j::Core::Equal
    include Neo4j::Core::Relationship
    include Neo4j::Core::Wrapper
    include Neo4j::Core::Index
  end
end