Nodes and Relationships

Introduction

To extend your graph data model to including customers order you will:

  1. Create Order nodes.

  2. Connect Customer nodes to Order nodes with a PURCHASED relationship.

  3. Run the import and view the results.

mermaid
Customer PURCHASED Order
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:

  1. Create a new Node label - Order

    + Node Label button highlighted
  2. Add the Order as the Label

  3. Select orders.csv as the Table

  4. Use the Map from table function to create the properties:

    Map from table button highlighted
  5. Select all the columns, except the customerId and employeeId.

    All columns selected except customerId and employeeId

    When you confirm the mapping, the properties, their data types, and column will be automatically mapped.

    Properties mapped from the table columns
  6. The orderId property should be selected as the unique ID.

  7. Run the import to create the Order nodes.

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:

cypher
Order nodes
MATCH (o:Order)
RETURN o
LIMIT 100
Result of the query showing the Order nodes

PURCHASED

You can now create the (Customer)-[:PURCHASED]→(Order) relationship.

  1. Drag a relationship from the Customer node to the Order node.

    Creating a relationship by dragging an arrow from the source node to the target node
  2. Set the Relationship Type to PURCHASED

  3. Select orders.csv as the Table

  4. The Node ID mapping tells Import how to connect the nodes.

    • Select customerID from the the Customer node

    • Select orderID from the Order node

      The setup of the purchased relationship, showing the node ID mapping
  5. Run the import

Need a working solution?

To update the graph data model with the solution, you can:

  1. Open Query and delete all the data from your instance:

    cypher
    MATCH (n) DETACH DELETE n
  2. Download the Customer-PURCHASED-Order data model - northwind-customer-order.zip.

  3. Use the …​ menu, select Open Model (with data), and select the northwind-customer-order.zip file you downloaded.

    …​ menu and  Open Model (with data) highlighted
  4. Run the import.

View customers and their orders

View the customer’s purchased orders:

cypher
Customer orders
MATCH (c:Customer)-[p:PURCHASED]->(o:Order)
RETURN c,p,o
LIMIT 100
Result of the query showing customers, their purchased relationships and the orders

Products

Repeat the same process to add Product nodes and ORDERS relationship to Order nodes.

mermaid
Order ORDERS Product
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:

  1. Add a new Product node label importing from products.csv

  2. Map the properties from the table

  3. Set the productId as the unique ID.

To create the relationship from Order to Product:

  1. Drag a new relationship from Order to Product with type ORDERS

  2. Use order-details.csv as the source table.

  3. Use the orderID and productID for the node ID mapping.

  4. Map the unitPrice, quantity and discount as relationship properties.

Need a working solution?

To update the graph data model with the solution, you can:

  1. Open Query and delete all the data from your instance:

    cypher
    MATCH (n) DETACH DELETE n
  2. Download the Customer-Order-Product data model - northwind-customer-order-product.zip.

  3. Use the …​ menu, select Open Model (with data), and select the northwind-customer-order-product.zip file you downloaded.

    …​ menu and  Open Model (with data) highlighted
  4. Run the import.

View customers, their orders, and products

View the customer’s purchased orders:

cypher
Customer orders
MATCH (c:Customer)-[p:PURCHASED]->(o:Order)-[or:ORDERS]->(pr:Product)
RETURN c,p,o,or,pr
LIMIT 100
Result of the query showing customers, their purchased relationships, the orders and products

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.

Chatbot

How can I help you today?