Getting Started Tutorial 2.x
Modeling the Order Entity

In real life we would browse the loaded data to try and better understand it. Let’s skip ahead and pretend that we have spoken to our Data Guru again.

The Order data we loaded is different than the Product data. Each order can have more than one Product. And for each product there can be a variable quantity.

Let’s look at order 1.

1,600,04/20/2017,05/02/2017,1000055,101591922267,4.5,1.0,3.92,different gallon,
1,600,04/20/2017,05/02/2017,1000153,164451986229,4.5,1.0,3.92,unwilling eave,
1,600,04/20/2017,05/02/2017,1000066,118675935929,33.99,2.0,32.53,stingy sharon,

We can see that there are three products in this order. We want to refer to them by sku: 101591922267, 164451986229, and 118675935929. Note that 118675935929 has a quantity of 2.0. Our data guru wants us to compute the total price for each order. To compute the price for this order we need to do some math.

(4.5 * 1) +
(4.5 * 1) +
(33.99 * 2)

We know that we want to harmonize three fields: id, price, and products. id is the unique identifier for each order. Price will be the total price of the entire order. Products will be an array of pointers to the Product entities in our Final database.

Let’s start modeling our Entity. Click on the Entities tab in the top navigation bar.

Click Entities Tab

  1. Click on the pencil icon for the Order entity.
  2. Click the + button below Properties to add a new row.
  3. Click in the area just below the key icon to make this row the primary key.
  4. Type in id as the Name.
  5. Change the Type to string.

Edit Entity

  1. Click the + button below Properties to add a new row.
  2. Type in price as the Name.
  3. Change the Type to decimal.

Edit Entity

  1. Click the + button below Properties to add a new row.
  2. Type in products as the Name.
  3. Change the Type to Product.
  4. Change the cardinality to 1..∞
  5. Click the SAVE button.

Edit Entity

After clicking Save you will be prompted whether you want to Update Indexes in MarkLogic or not.

Click YES.

One of the benefits of modeling your data with Entity Services is that we can use the model to create database configuration options automatically. This means we can update the necessary index settings bases on how you model your data. For the Product entity, we made sku the primary key. The Data Hub Framework will create a range index on the sku element.

Update Indexes

Up Next

Harmonizing the Order Data