Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create unique relationship #121

Merged
merged 5 commits into from
Nov 29, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/neography/relationship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ def create(type, from_node, to_node, props = nil)
rel
end

def create_unique(index, key, value, type, from_node, to_node, props = nil)
rel = Neography::Relationship.new(from_node.neo_server.create_unique_relationship(index, key, value, type, from_node, to_node, props))
rel.start_node = from_node
rel.end_node = to_node
rel.rel_type = type
rel
end

def load(rel, db = Neography::Rest.new)
raise ArgumentError.new("syntax deprecated") if rel.is_a?(Neography::Rest)

Expand Down
4 changes: 2 additions & 2 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ def create_relationship_auto_index(type = "exact", provider = "lucene")
@relationship_indexes.create_auto(type, provider)
end

def create_unique_relationship(index, key, value, type, from, to)
@relationship_indexes.create_unique(index, key, value, type, from, to)
def create_unique_relationship(index, key, value, type, from, to, props = nil)
@relationship_indexes.create_unique(index, key, value, type, from, to, props)
end

def add_relationship_to_index(index, key, value, id)
Expand Down
5 changes: 3 additions & 2 deletions lib/neography/rest/relationship_indexes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ def initialize(connection)
super(connection, :relationship)
end

def create_unique(index, key, value, type, from, to)
def create_unique(index, key, value, type, from, to, props = nil)
body = {
:key => key,
:value => value,
:type => type,
:start => @connection.configuration + "/node/#{get_id(from)}",
:end => @connection.configuration + "/node/#{get_id(to)}"
:end => @connection.configuration + "/node/#{get_id(to)}",
:properties => props
}
options = { :body => body.to_json, :headers => json_content_type }

Expand Down
5 changes: 3 additions & 2 deletions spec/unit/rest/relationship_indexes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ class Rest
"value" => "value",
"type" => "type",
"start" => "http://configuration/node/42",
"end" => "http://configuration/node/43"
"end" => "http://configuration/node/43",
"properties" => "properties"
}
connection.should_receive(:post).with("/index/relationship/some_index?unique", json_match(:body, expected_body))
subject.create_unique("some_index", "key", "value", "type", "42", "43")
subject.create_unique("some_index", "key", "value", "type", "42", "43", "properties")
end

it "adds a relationship to an index" do
Expand Down