We want to add some relationships between User nodes and Movie nodes so we can test our model.
In this challenge, you will create RATED relationships that include the rating property.
The sandbox window on the right creates one relationship between Sandy Jones and Apollo 13 with a rating of 5. Add additional MERGE
code in the query edit pane to create the remaining 4 relationships per the table below:
Note: The first MERGE
is already written for you.
User.name | Relationship | rating | Movie.title |
---|---|---|---|
'Sandy Jones' |
RATED |
5 |
'Apollo 13' |
'Sandy Jones' |
RATED |
4 |
'Sleepless in Seattle' |
'Clinton Spencer' |
RATED |
3 |
'Apollo 13' |
'Clinton Spencer' |
RATED |
3 |
'Sleepless in Seattle' |
'Clinton Spencer' |
RATED |
3 |
'Hoffa' |
Use MATCH
to find the User and Movie nodes, then use MERGE
to create the relationships between the two nodes.
Remember that you must specify or infer(left-to-right) a direction when you create a relationship.
You should create a total of 5 RATED relationships in the graph, each with a property, rating.
Validate Results
Once you have run the query, click the Check Database button and we will check the database for you.
Hint
You should add four more MERGE
clauses to the bottom of the statement:
MATCH (sandy:User {name: 'Sandy Jones'})
MATCH (clinton:User {name: 'Clinton Spencer'})
MATCH (apollo:Movie {title: 'Apollo 13'})
MATCH (sleep:Movie {title: 'Sleepless in Seattle'})
MATCH (hoffa:Movie {title: 'Hoffa'})
MERGE (sandy)-[:RATED {rating:5}]->(apollo)
Solution
Here is the completed Cypher statement with the four additional MERGE
clauses:
MATCH (sandy:User {name: 'Sandy Jones'})
MATCH (clinton:User {name: 'Clinton Spencer'})
MATCH (apollo:Movie {title: 'Apollo 13'})
MATCH (sleep:Movie {title: 'Sleepless in Seattle'})
MATCH (hoffa:Movie {title: 'Hoffa'})
MERGE (sandy)-[:RATED {rating:5}]->(apollo)
MERGE (sandy)-[:RATED {rating:4}]->(sleep)
MERGE (clinton)-[:RATED {rating:3}]->(apollo)
MERGE (clinton)-[:RATED {rating:3}]->(sleep)
MERGE (clinton)-[:RATED {rating:3}]->(hoffa)
Click Run in Browser to execute this query against your Sandbox.
Summary
In this challenge, you demonstrated that you can create some relationships to support your instance model.
Your instance model should now look like this:
In the next module, you will learn why and how to refactor your data model.