Using the ref() Function for Model Dependencies in dbt
📖 Scenario: You are working on a data project using dbt (data build tool). You have two models: one with raw sales data and another that summarizes total sales per product. You want to connect these models so the summary model uses the raw data model as its source.
🎯 Goal: Build two dbt models where the second model uses the ref() function to depend on the first model. This will help you understand how to manage dependencies between models in dbt.
📋 What You'll Learn
Create a dbt model called
raw_sales.sql with a simple SELECT statement.Create a variable called
summary_model_name with the value 'summary_sales'.Create a second dbt model called
summary_sales.sql that uses ref('raw_sales') in its FROM clause.Print the SQL query of the
summary_sales.sql model to see the final output.💡 Why This Matters
🌍 Real World
In real data projects, dbt helps organize SQL models and manage dependencies so that data transformations happen in the right order.
💼 Career
Understanding ref() is essential for data analysts and engineers using dbt to build reliable data pipelines.
Progress0 / 4 steps