Models and ref()

Models, ref() and the Dependency Graph

A model is a .sql file holding one SELECT; its file name becomes the table or view name. Models refer to each other with {{ ref('name') }}, which resolves to the right relation for the target and records an edge in the project's directed acyclic graph (DAG). dbt 37,942 derives the build order from the DAG and runs independent models in parallel. The book dimension joins a staging model to a seed:

models/marts/dim_book.sql: two ref() calls and a hashed surrogate keySQL
select {{ dbt.hash('b.book_id') }} as book_key,
       b.book_id, b.title, b.author, b.genre, g.genre_group, b.list_price,
       case when b.pages < 250 then 'short'
            when b.pages < 400 then 'medium' else 'long' end as length_band
from {{ ref('stg_books') }} b
left join {{ ref('genre_groups') }} g on g.genre = b.genre

The cross-database macro dbt.hash() compiles to md5(cast(b.book_id as TEXT)) on PostgreSQL 1,289 . A hashed key is the same on every rebuild, so the fact model computes it from book_id without joining the dimension, and both build in parallel. Selectors walk the DAG: +fct_sales is the model plus everything upstream:

Listing a model and its ancestors
dbt ls --select +fct_sales --resource-type model source
Output
booknest.marts.fct_sales
booknest.staging.stg_order_items
booknest.staging.stg_orders
source:booknest.shop.order_items
source:booknest.shop.orders

stg_orders+ selects downstream instead: everything a changed staging model feeds.