Skip to content

Commit

Permalink
property deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Dec 3, 2010
1 parent 9e3b38c commit 4541ce9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
12 changes: 7 additions & 5 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,13 @@ The Neo4j ID is available by using node.neo_id .
my_node.exist? # returns true/false if node exists in Neo4j

my_node = Node.create("age" => 31, "name" => "Max")
my_node[:age] #returns 31 # Get a node's property using [:key]
my_node.name #returns "Max" # Get a node's property as a method
my_node[:age] = 24 #changes age to 24 # Set a node's property using [:key] =
my_node.name = "Alex" #changes name to "Alex" # Set a node's property as a method

my_node[:age] #returns 31 # Get a node property using [:key]
my_node.name #returns "Max" # Get a node property as a method
my_node[:age] = 24 #changes age to 24 # Set a node property using [:key] =
my_node.name = "Alex" #changes name to "Alex" # Set a node property as a method
my_node[:name] = nil # Delete a node property using [:key] = nil
my_node.name = nil # Delete a node property by setting it to nil


See Neo4j API for:
* {Order}[http://components.neo4j.org/neo4j-examples/1.2.M04/apidocs/org/neo4j/graphdb/Traverser.Order.html]
Expand Down
6 changes: 4 additions & 2 deletions lib/neography/property.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ def []=(key, value)
k = key.to_s
if value.nil?
if self.is_a? Neography::Node
neo_server.remove_node_properties(self.neo_id, {k => value})
neo_server.remove_node_properties(self.neo_id, [key])
@table[key] = nil
else
neo_server.remove_relationship_properties(self.neo_id, {k => value})
neo_server.remove_relationship_properties(self.neo_id, [key])
@table[key] = nil
end
else
if self.is_a? Neography::Node
Expand Down
38 changes: 38 additions & 0 deletions spec/integration/node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,43 @@
new_node[:weight].should == 150
new_node[:eyes].should == "green"
end

it "can get node properties" do
new_node = Neography::Node.create("weight" => 150, "eyes" => "green")
new_node.weight.should == 150
new_node.eyes.should == "green"
end
end

describe "delete node properties" do
it "can delete node properties using []" do
new_node = Neography::Node.create("weight" => 150, "eyes" => "green")

new_node[:weight] = nil
new_node[:eyes] = nil

new_node[:weight].should be_nil
new_node[:eyes].should be_nil

existing_node = Neography::Node.load(new_node)
existing_node.weight.should be_nil
existing_node.eyes.should be_nil
end

it "can delete node properties" do
new_node = Neography::Node.create("weight" => 150, "eyes" => "green")

new_node.weight = nil
new_node.eyes = nil

new_node.weight.should be_nil
new_node.eyes.should be_nil

existing_node = Neography::Node.load(new_node)
existing_node.weight.should be_nil
existing_node.eyes.should be_nil
end
end


end

0 comments on commit 4541ce9

Please sign in to comment.