Introduction
To extend your graph data model to including customers order you will:
-
Create
Ordernodes. -
Connect
Customernodes toOrdernodes with aPURCHASEDrelationship. -
Run the import and view the results.
graph TD
Customer -->|PURCHASED| Order
Order(("<b>Order</b>"))
Customer(("<b>Customer</b>"))(Customer)-[:PURCHASED]→(Order)
Continue with the lesson to add Order nodes and PURCHASED relationships
Order nodes
Create the Order nodes:
-
Create a new Node label -
Order
-
Add the
Orderas the Label -
Select
orders.csvas the Table -
Use the Map from table function to create the properties:
-
Select all the columns, except the
customerIdandemployeeId.
When you confirm the mapping, the properties, their data types, and column will be automatically mapped.
-
The
orderIdproperty should be selected as the unique ID. -
Run the import to create the
Ordernodes.
Reconnect and authenticate
If you’re using a free Aura instance you will need to reconnect and enter your credentials before each run.
View the orders in the graph:
MATCH (o:Order)
RETURN o
LIMIT 100
PURCHASED
You can now create the (Customer)-[:PURCHASED]→(Order) relationship.
-
Drag a relationship from the
Customernode to theOrdernode.
-
Set the Relationship Type to
PURCHASED -
Select
orders.csvas the Table -
The Node ID mapping tells Import how to connect the nodes.
-
Select
customerIDfrom the theCustomernode -
Select
orderIDfrom theOrdernode
-
-
Run the import
Need a working solution?
To update the graph data model with the solution, you can:
-
Open Query and delete all the data from your instance:
cypherMATCH (n) DETACH DELETE n -
Download the Customer-PURCHASED-Order data model - northwind-customer-order.zip.
-
Use the
…menu, select Open Model (with data), and select the northwind-customer-order.zip file you downloaded.
-
Run the import.
View customers and their orders
View the customer’s purchased orders:
MATCH (c:Customer)-[p:PURCHASED]->(o:Order)
RETURN c,p,o
LIMIT 100
Products
Repeat the same process to add Product nodes and ORDERS relationship to Order nodes.
graph TD
Order -->|ORDERS<br/>unitPrice<br/>quantity<br/>discount| Product
Product(("<b>Product</b>"))
Order(("<b>Order</b>"))To include the product nodes you will need to:
-
Add a new
Productnode label importing fromproducts.csv -
Map the properties from the table
-
Set the
productIdas the unique ID.
To create the relationship from Order to Product:
-
Drag a new relationship from
OrdertoProductwith typeORDERS -
Use
order-details.csvas the source table. -
Use the
orderIDandproductIDfor the node ID mapping. -
Map the
unitPrice,quantityanddiscountas relationship properties.
Need a working solution?
To update the graph data model with the solution, you can:
-
Open Query and delete all the data from your instance:
cypherMATCH (n) DETACH DELETE n -
Download the Customer-Order-Product data model - northwind-customer-order-product.zip.
-
Use the
…menu, select Open Model (with data), and select the northwind-customer-order-product.zip file you downloaded.
-
Run the import.
View customers, their orders, and products
View the customer’s purchased orders:
MATCH (c:Customer)-[p:PURCHASED]->(o:Order)-[or:ORDERS]->(pr:Product)
RETURN c,p,o,or,pr
LIMIT 100
Next
Lesson Summary
In this lesson, you learned extend your graph data model by adding new nodes and relationships
In the next challenge, you will review the data set, identify new nodes and relationships and add them to the graph.