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

refactor: render relationship test on defining model #183

Merged

Conversation

mascah
Copy link
Contributor

@mascah mascah commented Apr 2, 2021

resolves #181

Description

Currently a relationship test is rendered on the model that the test points "to".
This change reverses the direction so that the relationship test renders on the model
that the test is defined in, or the "from" model pointing to the parent model.

schema.yml

version: 2

models:
    - name: my_first_dbt_model
      description: "A starter dbt model"
      columns:
          - name: id
            description: "The primary key for this table"
            tests:
                - unique
                - not_null

    - name: my_second_dbt_model
      description: "A starter dbt model"
      columns:
          - name: id
            description: "The primary key for this table"
            tests:
                - unique
                - not_null
                - relationships:
                    to: ref('my_first_dbt_model')
                    field: id

Screen Shot 2021-04-01 at 7 50 14 PM

Checklist

  • I have signed the CLA
  • I have generated docs locally, and this change appears to resolve the stated issue
  • I have updated the CHANGELOG.md and added information about my change to the "dbt next" section.

@cla-bot cla-bot bot added the cla:yes label Apr 2, 2021
@mascah mascah force-pushed the relationship-test-on-defining-model branch 3 times, most recently from 9176843 to 4517ee4 Compare April 2, 2021 02:20
Copy link
Contributor

@jtcohen6 jtcohen6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thanks @mascah! Could you also add yourself as a contributor in the changelog? (See previous versions for examples)

I'll follow up with another PR that adds a relationships test to one of the models in the ci-project, so that we can have this appear in our PR deploy-preview site.

Currently a relationship test is rendered on the model that the test points "to".
This change reverses the direction so that the relationship test renders on the model
that the test is defined in, or the "from" model pointing to the parent model.
@mascah mascah force-pushed the relationship-test-on-defining-model branch from 4517ee4 to 392ba77 Compare April 12, 2021 15:24
@mascah
Copy link
Contributor Author

mascah commented Apr 12, 2021

This looks great, thanks @mascah! Could you also add yourself as a contributor in the changelog? (See previous versions for examples)

Done!

I'll follow up with another PR that adds a relationships test to one of the models in the ci-project, so that we can have this appear in our PR deploy-preview site.

Just noticed that it looks like one already exists, hopefully this covers what you were thinking and saves you the time!

https://github.com/fishtown-analytics/dbt-docs/blob/97570c58c474dfbba0b145576792bc8e3ead6c5c/ci-project/models/marts/core/schema.yml#L49-L51

Copy link
Contributor

@jtcohen6 jtcohen6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed that it looks like one already exists, hopefully this covers what you were thinking and saves you the time!

Well spotted! Even better.

LGTM, thanks @mascah!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Relationship tests rendering in docs on the to model instead of the model the test was defined in
2 participants