Database Reference
In-Depth Information
Retrieving Relationships
Once a relationship has been created between one or more nodes, the relationship can be retrieved based on a node
(Listing 10-9).
Listing 10-9. Retreiving relationships.
require 'neography'
neo = Neography::Rest.new({ :protocol => 'http://', :server => 'localhost', :port => 7474,
:directory => '/db/data'})
# get the related nodes
greg = neo.get_node(1)
daniel = neo.get_node(10)
# find their directed relationship
rels = neo.get_node_relationships_to(greg, daniel, "in", "FOLLOWS")
Deleting a Relationship
Once a relationship's graph id has been set and saved into the database, it becomes eligible to be removed when
necessary. To remove a relationship, set it as a relationship object instance and then call the delete method for the
relationship (Listing 10-10).
Listing 10-10. Deleting a Relationship
require 'neography'
neo = Neography::Rest.new({ :protocol => 'http://', :server => 'localhost', :port => 7474,
:directory => '/db/data'})
# get the related nodes
greg = neo.get_node(1)
daniel = neo.get_node(10)
# find their directed relationship
rels = neo.get_node_relationships_to(greg, daniel, "in", "FOLLOWS")
# delete the relationship
rels.each { |rel_id| neo.delete_relationship(rel_id) }
Using Labels
Labels function as specific meta-descriptions that can be applied to nodes. Labels were introduced in Neo4j 2.0 in
order to help in querying and can also function as a way to quickly create a subgraph.
 
Search WWH ::




Custom Search