Relations within the same table

Hi
I’m trying to create a basic app to track inventory of components.
Each component may require other components, thus creating a kind of dependancy-tree.

For example, lets say the “top level” component is a Car.

So i’d have four components.
Car
Wheel
Hub
Tyre

1 Car requires 4 Wheels. And each wheel requires 1 Hub and 1 Tyre.

I’m not sure how to set up the relations in Glide.

In a traditional relational DB i would have done it like this:
image

How can this be done in Glide?

Thanks!

I would do it like this.

Components table

RowID Name
C001 Car
C002 Wheel
C003 Hub
C004 Tyre

Dependencies table

RowID Parent Component ID Child Component ID Quantity
D001 C001 C002 4
D002 C002 C003 1
D003 C002 C004 1

However, this gets complex when you want to know how many hubs and tyres would you need to make a car, for example, and if you have more than just 2 levels like this one. It might have to involve some sort of JSON manipulation.

Thanks for the respose.
Yes that table structure looks the same as I had in mind.

But how do you actually set that up in Glide? This is the first time I’m using it, and not familiar with it.

I have set up the component table, that’s fine and straightforward. but how do i set the dependencies table? I can’t see how to do it :frowning:

Do you mean how you fill that table from a screen on the Components table? Do you want to use a form or any other methods?

Hmm, I expected to need to set some constraints on the table to do this linking.
Is it good enough to just rely on it being a text field without any validation and just rely on the front-end to ensure that valid IDs are inserted?

I would suggest checking this. You can either use a form button or a form container.

Your form would contain a choice component to add the child component’s ID, and a number entry for the quantity. Then you pass over the parent’s ID. If you’re on the details screen of the parent component already, it’s straightforward to pass it as a special value.