Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add relation examples for {{this}} #4011

Merged
merged 24 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
27d3aa6
add relation examples for {{this}} jinja function
mirnawong1 Sep 4, 2023
e3effaa
fix keywords
mirnawong1 Sep 4, 2023
7fc7cad
fix keyword error
mirnawong1 Sep 4, 2023
a438f7e
more keywords
mirnawong1 Sep 4, 2023
36f0620
Merge branch 'current' into mwong-add-this-options
mirnawong1 Sep 4, 2023
b9d63f8
Merge branch 'current' into mwong-add-this-options
mirnawong1 Sep 5, 2023
b7eff9c
Merge branch 'current' into mwong-add-this-options
mirnawong1 Sep 6, 2023
d392f4f
add link to this on relation page
mirnawong1 Sep 6, 2023
4df9c49
Merge branch 'current' into mwong-add-this-options
mirnawong1 Sep 7, 2023
1379c87
remove duplication
mirnawong1 Sep 7, 2023
3772d66
simplify example paragraph
mirnawong1 Sep 7, 2023
0c58efa
Merge branch 'current' into mwong-add-this-options
mirnawong1 Sep 7, 2023
2e0af5d
Merge branch 'current' into mwong-add-this-options
mirnawong1 Sep 8, 2023
ef4e099
Merge branch 'current' into mwong-add-this-options
mirnawong1 Sep 11, 2023
5415e20
clarify this per convo w joel
mirnawong1 Sep 15, 2023
4dd296e
Merge branch 'current' into mwong-add-this-options
mirnawong1 Sep 15, 2023
cd5d6bc
remove
mirnawong1 Sep 15, 2023
9d3684c
Update website/docs/reference/dbt-classes.md
mirnawong1 Sep 18, 2023
3bb2185
Update website/docs/reference/dbt-jinja-functions/source.md
mirnawong1 Sep 18, 2023
9bbdb22
Update website/docs/reference/dbt-jinja-functions/ref.md
mirnawong1 Sep 18, 2023
773e8a0
Merge branch 'current' into mwong-add-this-options
mirnawong1 Sep 18, 2023
56848ee
Update website/docs/reference/dbt-jinja-functions/this.md
mirnawong1 Sep 18, 2023
a64c1dd
Update website/docs/reference/dbt-classes.md
mirnawong1 Sep 18, 2023
c0a48a4
Merge branch 'current' into mwong-add-this-options
mirnawong1 Sep 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions website/docs/reference/dbt-classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ These classes are often useful when building advanced dbt models and macros.

The `Relation` object is used to interpolate schema and <Term id="table" /> names into SQL code with appropriate quoting. This object should _always_ be used instead of interpolating values with `{{ schema }}.{{ table }}` directly. Quoting of the Relation object can be configured using the [`quoting` config](/reference/project-configs/quoting).


### Creating relations

A `Relation` can be created by calling the `create` class method on the `Relation` class.
Expand All @@ -32,6 +33,7 @@ class Relation:

### Using relations

In addition to `api.Relation.create`, dbt returns a Relation when you use [`ref`](/reference/dbt-jinja-functions/ref), [`source`](/reference/dbt-jinja-functions/source) or [`this`](/reference/dbt-jinja-functions/this).
<File name='relation_usage.sql'>

```jinja2
Expand Down
1 change: 1 addition & 0 deletions website/docs/reference/dbt-jinja-functions/ref.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ from {{ref('model_a')}}
`ref()` is, under the hood, actually doing two important things. First, it is interpolating the schema into your model file to allow you to change your deployment schema via configuration. Second, it is using these references between models to automatically build the dependency graph. This will enable dbt to deploy models in the correct order when using `dbt run`.

The `{{ ref }}` function returns a `Relation` object that has the same `table`, `schema`, and `name` attributes as the [{{ this }} variable](/reference/dbt-jinja-functions/this).
- Note &mdash; Prior to dbt v1.6, the dbt Cloud IDE returns `request` as the result of `{{ ref.identifier }}`.

## Advanced ref usage

Expand Down
1 change: 1 addition & 0 deletions website/docs/reference/dbt-jinja-functions/source.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This function:
- Creates dependencies between a source and the current model, which is useful for documentation and model selection
- Compiles to the full object name in the database


## Related guides
- [Using sources](/docs/build/sources)

Expand Down
11 changes: 10 additions & 1 deletion website/docs/reference/dbt-jinja-functions/this.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ title: "about this"
sidebar_label: "this"
id: "this"
description: "Represents the current model in the database."
keywords:
- relation, relation object, this function, this jinja, this.database, this.schema, this.identifier
meta:
label: 'this'
---

`this` is the database representation of the current model. It is useful when:
- Defining a `where` statement within [incremental models](/docs/build/incremental-models)
- Using [pre or post hooks](/reference/resource-configs/pre-hook-post-hook)

`this` is a [Relation](/reference/dbt-classes#relation), and as such, properties such as `{{ this.database }}` and `{{ this.schema }}` compile as expected.
`this` is a [Relation](/reference/dbt-classes#relation), and as such, properties such as `{{ this.database }}` and `{{ this.schema }}` compile as expected.
- Note &mdash; Prior to dbt v1.6, the dbt Cloud IDE returns `request` as the result of `{{ ref.identifier }}`.

`this` can be thought of as equivalent to `ref('<the_current_model>')`, and is a neat way to avoid circular dependencies.

Expand Down Expand Up @@ -54,3 +59,7 @@ from raw_app_data.events
```

</File>




Loading