SEARCH:

Fetching a Price

Andromeda's automations fall into two basic abilities. One of these is the ability to calculate values within a row, such as multiplying price times quantity. The other ability is all about moving values from one table to another. There are several ways to do this but the method that is probably simplest and most intuitive is the FETCH.

A FETCH copies a value from a parent table to a child table. The standard example is copying price from an items table onto an order. Let's begin with the items table.

column sku:
    type_id: vchar
    colprec: 15
    description: SKU
table items:
    module: inventory
    description: Items
    
    column sku:
        primary_key: Y
        uisearch: Y
    column price:
        uisearch: Y

Now we want the orders table to always get the price when a new order is entered

table order_lines:
    module: orders
    description: Order Lines
    
    # The foreign key means the order_lines table will
    # automatically get the column “sku”
    foreign_key items:
    column price:
        automation_id: FETCH
        auto_formula: items.price

The price will be copied into the ORDER_LINES table whenever the value of SKU changes in the ORDER_LINES table.