%% Update Multiple Relationships
% Create two relationships between nodes in a Neo4j® database, update the properties of the relationships, and display the properties.
% Assume that you have graph data stored in a Neo4j database that represents a social neighborhood. This database has seven nodes and eight relationships. Each node has only one unique property key name with a value ranging from User1 through User7. Each relationship has the type knows.
% Create a Neo4j database connection using the URL http://localhost:7474/db/data, user name neo4j, and password matlab.

url = 'http://localhost:7474/db/data';
username = 'neo4j';
password = 'matlab';

neo4jconn = neo4j(url,username,password);

%
% Check the Message property of the Neo4j connection object neo4jconn. The blank Message property indicates a successful connection.

neo4jconn.Message

%
% Search for the node with the label Person and the property key name set to the value User7 by using the Neo4j database connection.

nlabel = 'Person';
user7 = searchNode(neo4jconn,nlabel,'PropertyKey','name', ...
    'PropertyValue','User7');

%
% Create two nodes in the database using the Neo4j database connection. Use the 'Labels' name-value pair argument to specify the label Person for each node.

label = 'Person';
user8 = createNode(neo4jconn,'Labels',label);
user9 = createNode(neo4jconn,'Labels',label);

%
% Create two relationships using the Neo4j database connection. Specify the relationship types as works with and studies with. The two relationships are:
% User8 works with User7
% User8 studies with User9
% relationinfo is a table that contains the relationship and node information.

startnode = [user8,user8];
endnode = [user7,user9];
relationtype = {'works with','studies with'};
relationinfo = createRelation(neo4jconn,startnode,endnode,relationtype);

%
% Create a table that defines the properties. Here, User8 works with User7 in the workplace, and User8 studies with User9 in the library. Also, User8 started working with User7 on January 2, 2017, and User8 started studying with User9 on March 6, 2017.

properties = table(["Workplace";"Library"],["01/02/2017";"03/06/2017"], ...
    'VariableNames',{'Location','Date'});

%
% Update both relationships with these properties.

relations = relationinfo.RelationObject;
relationinfo = updateRelation(neo4jconn,relations,properties)

%
% relationinfo is a table with these variables:
% Start node identifier
% Relationship type
% End node identifier
% Relationship data
% Neo4jRelation object
% Display the updated properties of the relationships.

relationinfo.RelationData{1}
relationinfo.RelationData{2}

%
% Close the database connection.

close(neo4jconn)

%
% Copyright 2018 The MathWorks, Inc.