Creating a relationship to multiple tables

Is there a way to create a relationship with multiple tables?
For example: We wanted to have a unified State ledger that would have all the states of everything that required a state in the system. A user could have a State (verified, unverified) and an Account could have a State (pending, complete, something-else, thing2). So, in my State table, I wanted to have a relationship back to whatever the entity is. So state would have an “relatedEntity” column that could relate to BOTH User and Account. Is it possible to draw a relationship to multiple tables like that?

Hey @jamie-share - we currently do not have a concept of polymorphic relations in 8base. It’s something we’re exploring the best way to implement.

In your example, I’d suggest one of two approaches.

  1. Create a Switch type filed on both tables with the relevant States for either.

  2. Create a table called States and create 2 relationships to both the Users and Accounts table.

One of the challenges here is that in GraphQL an array of objects shouldn’t return mix types. Therefore, the query:

query {
  statesList { 
    items {
      relatedEntity { ...HAS TO BE ONE TYPE, not variable } 
    } 
  }
}

Wouldn’t be in-line with the specification.

Perhaps I’m misunderstanding, but isn’t that handled by GQL Union types? https://graphql.org/learn/schema/#union-types

Hello!

Sorry, but Union is not supported.

Lada Kokotova | Technical Support Engineer

Hi Lada,

I just wanted to point out that the GQL specification isn’t the problem here as far as I can see. Of course I totally understand if 8Base can’t make use of it for some architectural reason though. :slight_smile:

Hey Marky - yes we currently don’t support Union types in our implementation. One day!