Docs‎ > ‎Reactive Logic Tutorial‎ > ‎

Sample Database

The following image illustrates the sample database. This database is used extensively in the Reactive Logic Tutorial.

Relationship Examples

The sample database illustrates classic examples of common relationship patterns:

One to Many

See the relationship between Customer (Parent) and Orders (Child).

One to Many Self Relationship

See the self-relationship from Departments to itself.

Many to Many Self Relationship

The product_billofmaterials table represents that:
  • A "kit" product may have many "component" products. For example, a wing can consist of engines and bolts.
  • A "component" product may be a component of many kits. For example, bolts are used in wings and engines.
Note: A product, such as a wing, can be a component (of a plane) and a kit.

The sample database contains the following products:

Consider the following example:
  • A Boing 747 consists of a Fuselage, Wing, and Bolts 
  • A Wing consists of an Engine and Bolts
That is represented by rows in the product_billofmaterials table, as follows:

Products are entered into the same products table but are differentiated, as follows:

  • Kit: A product with components. For example, Boing, Wing.
  • Component: A product that is a component. For example, Fuselage, Bolt, Wing, Engine.
Note: Wing is a kit and a component, a recursive relationship.

The following are relationships from product to product_billofmaterials:

  • inKits: product implemented by foreign key product_name, so:
    • product.inKits returns the product_billofmaterials identifying the kits in which a product is a member. So, bolt.inKits returns ( (Boing, Bolt) and (Wing, Bolt) )
    • product_billofMaterials.product returns the component. So, (Boing, Bolt) returns Bolt

  • components: kit implemented by foreign key product_name_kit, so:
    • product.components returns the product_billofmaterials identifying the components in this kit. So, boing.components returns ( (Boing, Bolt) (Boing, Fuselage) (Boing, Wing) )
    • ProductBillofmaterials.kit returns the kit. So, (Boing, Bolt) returns Boing.

A Boing price calculates to $10,300:

  • 1 Fuselage @ $1300 = $1,300
  • 100 Bolts @ $10 = $1,000
  • 2 Wings @ $4,000 = $8,000, which itself is calculated as...
    • 2 Engines @ $1,500 = $3,000
    • 100 Bolts @ $10 = $1,000
Ordering a Boing 747 effects Product qtyOnHand, as follows:
  • totalQtyOrdered[Engines] increased by 4 (2 for each of 2 wings).
  • totalQtyOrdered[Bolts] increased by 300 (100 from Boing, 100 for each of 2 wings).
Ordering the Boing 747 inserts the following LineItems:
  • Boing 747
    • Bolts
    • Wing
      • Bolts
      • Engine
    • Fuselage