Skip to content

[Enh]: Support relationships between views (and tables). #3079

@JerryNixon

Description

@JerryNixon

What

Allow entities backed by views to participate in relationships.

Supported combinations

  • view → view
  • view → table
  • table → view

No new configuration syntax. Existing entities.<name>.relationships settings continue to work.

Unlimited combinations

flowchart LR
    Table1
    Table2
    View1
    View2

    Table1 --> Table2
    Table1 --> View1
    View1 --> View2
    View1 --> Table2
Loading

Note

Stored procedures cannot be related.

Why

Today relationships only work between table entities.

However, DAB already allows relationships to be defined in configuration without requiring database FK constraints. If a relationship can be described using fields in configuration, the engine should be able to generate the join even when the underlying object is a view.

This enables common read models where views shape the data exposed through the API. A view such as SeriesActors can already be exposed as an entity, but it cannot currently participate in relationships.

Example

View → table relationship

Exactly the same syntax as before

"entities": {
  "BooksView": {
    "source": { "object": "dbo.vw_books_details", "type": "view" },
    "relationships": {
      "publisher": {
        "cardinality": "one",
        "target.entity": "Publisher",
        "relationship.fields": [ "publisher_id:id" ]
      }
    }
  }
}

View → view relationship

Exactly the same syntax as table

"relationships": {
  "authors": {
    "cardinality": "many",
    "target.entity": "AuthorsView",
    "relationship.fields": [ "id:book_id" ]
  }
}

Metadata

Metadata

Labels

2.1enhancementNew feature or requestgraphqlhas-prmssql pgsql mysqlan issue that applies to all relational databases, same as labeling with `mssql` `mysql` and `pgsql`

Projects

Status

Review In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions