Dev.to AI 🤖 Ai 👁 0 📖 3 min read

How Relationship Lineage Inheritance Works Across dbt Models

When a dbt model renames a column, should the original database relationship still be available to developers? In many cases, yes. But determining when that relationship can safely be inherited requires more than matchi

How Relationship Lineage Inheritance Works Across dbt Models

When a dbt model renames a column, should the original database relationship still be available to developers?

In many cases, yes. But determining when that relationship can safely be inherited requires more than matching column names.

We've been working on this problem with IntaLink for dbt, a VS Code extension for relationship-aware SQL development.

Let's walk through a simplified example.

1. Start with a Reviewed Source Relationship

Suppose we have two source tables:

orders.customer_ref
customers.customer_id

Database profiling suggests that multiple orders can reference one customer.

The relationship is reviewed and included in an IntaLink relationship set.

At this point, the relationship is associated with the original database fields.

2. Rename the Column in a Staging Model

In stg_orders.sql:

SELECT
    order_id,
    customer_ref AS customer_key,
    order_amount
FROM {{ source('commerce', 'orders') }}

The original column name has changed, but the underlying values have not.

If the lineage can be established, the relationship associated with customer_ref can remain relevant to customer_key.

3. Pass the Column Through Another Model

In int_customer_orders.sql:

WITH orders AS (
    SELECT *
    FROM {{ ref('stg_orders') }}
)

SELECT
    order_id,
    customer_key,
    order_amount
FROM orders

The relationship now needs to be traced through multiple transformation layers.

IntaLink for dbt supports relationship lineage inheritance across eligible transformations such as direct column renames, certain casts, CTEs, SELECT *, and nested ref() calls.

This helps make reviewed relationship information available beyond the original source table.

4. Use the Relationship During JOIN Development

Consider a downstream model:

SELECT
    o.order_id,
    o.order_amount,
    c.customer_name
FROM {{ ref('int_customer_orders') }} AS o
LEFT JOIN {{ ref('stg_customers') }} AS c
    ON o.customer_key = c.customer_id

Assuming stg_customers.customer_id also has a supported lineage path to the original customer identifier, the inherited relationship can inform JOIN suggestions.

IntaLink for dbt can surface eligible table and field suggestions directly in VS Code.

[INSERT ORIGINAL SCREENSHOT 2 — JOIN table suggestions]

The extension uses available relationship information to suggest related tables and models.

5. Not Every Transformation Should Inherit a Relationship

Consider this expression:

CONCAT(region_code, '-', customer_ref)
    AS customer_key

This creates a new identifier.

The original relationship between customer_ref and customer_id should not automatically be assumed to apply to this expression.

Even a CAST may change values or uniqueness depending on the data type and transformation.

That's why relationship inheritance must be limited to supported, eligible lineage paths.

It is not a guarantee of semantic equivalence.

6. Relationship Evidence Still Matters

A developer should be able to inspect the information behind a JOIN suggestion.

IntaLink exposes supporting evidence such as:

  • Value inclusion.
  • Distinct-value statistics.
  • Inferred cardinality.
  • Review status.
  • Relationship source information.

[INSERT ORIGINAL SCREENSHOT 3 — JOIN condition and relationship evidence]

Supporting evidence displayed alongside a candidate JOIN condition.

The screenshots illustrate the extension's general suggestion and evidence interfaces. The SQL examples above explain the inheritance concept.

Inherited relationship information does not replace dbt tests or validation of the transformed dataset.

7. How to Try It

IntaLink Cloud handles relationship discovery and review.

The VS Code extension consumes sealed relationship sets and uses them alongside information from the local dbt project.

For the extension workflow, you'll need a supported dbt project, a generated target/manifest.json, and an available sealed relationship set.

We've also built an interactive browser-based playground so developers can explore the JOIN suggestion workflow before installing the extension.

Try Interactive Demo

VS Code Marketplace

The broader idea is simple: database relationships should become reusable engineering knowledge, rather than something developers repeatedly investigate as models evolve.

Disclosure: I'm part of the Arisyn team developing IntaLink for dbt.

📰 Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.