10

I’m trying to make one model in dbt depend on another (trying to run the second model after the first one is completely finished), but I’m confused, when to use ref() or source()?

What is the difference between them?

Val Berthe
  • 1,899
  • 1
  • 18
  • 33
Sara
  • 111
  • 1
  • 5
  • These docs will help: https://docs.getdbt.com/reference/dbt-jinja-functions/ref and https://docs.getdbt.com/reference/dbt-jinja-functions/source – Aleix CC Sep 22 '22 at 16:10

1 Answers1

15

Using ref creates the lineage for your DAG and will run the predecessor models. Using source references a base table that is not necessarily a model. Rule of thumb is use source in your base models and everything else should use ref.

Example - Green nodes represent tables ingested into your DWH. The blue/red nodes are DBT models. enter image description here

Adam Kipnis
  • 10,175
  • 10
  • 35
  • 48