The Mental Model
dbt lets analytics engineers build data transformations as version-controlled SQL files. The dependency graph comes from source declarations and ref calls.
Think of each dbt model as a recipe. ref() means "use the output of another recipe." dbt reads the recipes and decides the safe build order.
Dataset reference: ecommerce tables and grain assumptions.
Read dependencies from a model
Save the following model as models/marts/fct_orders.sql in a dbt project that already defines stg_orders.
select order_id, customer_id, amount
from {{ ref('stg_orders') }}
where status = 'completed'
The ref call resolves the relation and records a dependency. dbt compiles the template into warehouse SQL; the configured materialization determines whether the result becomes a view, table, or another supported relation. A file named fct_orders does not automatically become a table.
Expected dependency: source orders to stg_orders to fct_orders. Compile the project and inspect the resolved relation before a build. See the dbt ref reference for dependency behavior.
Interactive Check
Question: If fct_orders uses ref("stg_orders"), which model must build first?
Reveal the answer
stg_orders must build first. The ref call creates a dependency edge from fct_orders back to stg_orders.
Practice: Order the dbt DAG
Put shuffled dbt models into the correct build order.
Use the guided lab below to record your result, assumptions, and the check that would catch an incorrect result.