H18 Define a relational model
Use your current course session. Preparation and course runner · R script ↓
H18 Define a relational model
Goal: Describe tables and their relationships together.
Prerequisites: H17; dm is a core dependency.
A dm model retains multiple tables. It does not automatically flatten them into one output table.
training_step(
"H18",
{
portfolio_model <- dm::dm(
policies = linked_policies,
customers = customers,
brokers = brokers
) |>
dm::dm_add_pk(policies, policy_id) |>
dm::dm_add_pk(customers, customer_id) |>
dm::dm_add_pk(brokers, broker_id) |>
dm::dm_add_fk(policies, customer_id, customers) |>
dm::dm_add_fk(policies, broker_id, brokers)
print(portfolio_model)
},
needs = c("H17")
)Expected result: Three tables and two foreign-key relationships.
Task: Which table holds the region?
Show solution
customers. The model preserves that normalized structure.