From 058ee5927e6d0098388995132afdb84028a4df2e Mon Sep 17 00:00:00 2001 From: Doug Beatty <44704949+dbeatty10@users.noreply.github.com> Date: Fri, 8 Mar 2024 18:37:04 -0500 Subject: [PATCH 1/5] Update example for overriding the `ref` macro --- website/docs/reference/dbt-jinja-functions/builtins.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/website/docs/reference/dbt-jinja-functions/builtins.md b/website/docs/reference/dbt-jinja-functions/builtins.md index 7d970b9d5e1..f4bf2e5fc20 100644 --- a/website/docs/reference/dbt-jinja-functions/builtins.md +++ b/website/docs/reference/dbt-jinja-functions/builtins.md @@ -22,8 +22,10 @@ Using the `builtins` variable in this way is an advanced development workflow. U ::: - -From dbt v1.5 and higher, use the following macro to extract user-provided arguments, including version, and call the builtins.ref() function with either a single modelname argument or both packagename and modelname arguments, based on the number of positional arguments in varargs: + +From dbt v1.5 and higher, use the following macro to override the `ref` method available in the model compilation context to return a [Relation](/reference/dbt-classes#relation) with the database name overriden to `dev`. + +It includes logic to extract user-provided arguments, including version, and call the builtins.ref() function with either a single modelname argument or both packagename and modelname arguments, based on the number of positional arguments in varargs.

From 75b277019a46722b510d8e83f5f6231c8cefde7c Mon Sep 17 00:00:00 2001 From: Doug Beatty <44704949+dbeatty10@users.noreply.github.com> Date: Fri, 8 Mar 2024 18:45:30 -0500 Subject: [PATCH 2/5] Update indentation --- website/docs/reference/dbt-jinja-functions/builtins.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/website/docs/reference/dbt-jinja-functions/builtins.md b/website/docs/reference/dbt-jinja-functions/builtins.md index f4bf2e5fc20..243558b9a98 100644 --- a/website/docs/reference/dbt-jinja-functions/builtins.md +++ b/website/docs/reference/dbt-jinja-functions/builtins.md @@ -31,16 +31,16 @@ It includes logic to extract user-provided arguments, including version Date: Fri, 8 Mar 2024 18:46:55 -0500 Subject: [PATCH 3/5] Restore macro name --- website/docs/reference/dbt-jinja-functions/builtins.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/website/docs/reference/dbt-jinja-functions/builtins.md b/website/docs/reference/dbt-jinja-functions/builtins.md index 243558b9a98..246ea1b7af7 100644 --- a/website/docs/reference/dbt-jinja-functions/builtins.md +++ b/website/docs/reference/dbt-jinja-functions/builtins.md @@ -31,6 +31,8 @@ It includes logic to extract user-provided arguments, including version Date: Fri, 8 Mar 2024 18:47:42 -0500 Subject: [PATCH 4/5] Handle `v` keyword argument for model versions --- website/docs/reference/dbt-jinja-functions/builtins.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/reference/dbt-jinja-functions/builtins.md b/website/docs/reference/dbt-jinja-functions/builtins.md index 246ea1b7af7..2f96e16bd3d 100644 --- a/website/docs/reference/dbt-jinja-functions/builtins.md +++ b/website/docs/reference/dbt-jinja-functions/builtins.md @@ -34,7 +34,7 @@ It includes logic to extract user-provided arguments, including version Date: Fri, 8 Mar 2024 18:53:27 -0500 Subject: [PATCH 5/5] Make the second example work both pre- and post- v1.5 --- website/docs/reference/dbt-jinja-functions/builtins.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/website/docs/reference/dbt-jinja-functions/builtins.md b/website/docs/reference/dbt-jinja-functions/builtins.md index 2f96e16bd3d..9f1d139ab20 100644 --- a/website/docs/reference/dbt-jinja-functions/builtins.md +++ b/website/docs/reference/dbt-jinja-functions/builtins.md @@ -75,14 +75,10 @@ From dbt v1.4 and lower, use the following macro to override the `ref` method av ```
-The ref macro can also be used to control which elements of the model path are rendered when run, for example the following macro overrides the `ref` method to render only the schema and object identifier, but not the database reference i.e. `my_schema.my_model` rather than `my_database.my_schema.my_model`. This is especially useful when using snowflake as a warehouse, if you intend to change the name of the database post-build and wish the references to remain accurate. +Logic within the ref macro can also be used to control which elements of the model path are rendered when run, for example the following logic renders only the schema and object identifier, but not the database reference i.e. `my_schema.my_model` rather than `my_database.my_schema.my_model`. This is especially useful when using snowflake as a warehouse, if you intend to change the name of the database post-build and wish the references to remain accurate. ``` --- Macro to override ref and to render identifiers without a database. -{% macro ref(model_name) %} - - {% do return(builtins.ref(model_name).include(database=false)) %} - -{% endmacro %} + -- render identifiers without a database + {% do return(rel.include(database=false)) %} ```