# Relations within the same table

**URL:** <https://community.glideapps.com/t/relations-within-the-same-table/75744>\
**Category:** Ask for Help\
**Created:** [August 20, 2024, 5:36pm UTC](https://community.glideapps.com/t/relations-within-the-same-table/75744 "2024-08-20T17:36:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![RobFy](https://avatars.discourse-cdn.com/v4/letter/r/e9a140/32.png) [@RobFy](https://community.glideapps.com/u/RobFy)\
**Post date:** [August 20, 2024, 5:36pm UTC](https://community.glideapps.com/t/relations-within-the-same-table/75744/1 "2024-08-20T17:36:28Z")

</div>

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](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/2/9/29f719c3bc9a34780ae0bccf7fa7bac6c1093920.png)

How can this be done in Glide?

Thanks!

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [August 20, 2024, 11:20pm UTC](https://community.glideapps.com/t/relations-within-the-same-table/75744/2 "2024-08-20T23:20:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![RobFy](https://avatars.discourse-cdn.com/v4/letter/r/e9a140/32.png) [@RobFy](https://community.glideapps.com/u/RobFy)\
**Post date:** [August 21, 2024, 12:08am UTC](https://community.glideapps.com/t/relations-within-the-same-table/75744/3 "2024-08-21T00:08:15Z")

</div>

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 ☹

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [August 21, 2024, 12:18am UTC](https://community.glideapps.com/t/relations-within-the-same-table/75744/4 "2024-08-21T00:18:11Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![RobFy](https://avatars.discourse-cdn.com/v4/letter/r/e9a140/32.png) [@RobFy](https://community.glideapps.com/u/RobFy)\
**Post date:** [August 21, 2024, 10:46am UTC](https://community.glideapps.com/t/relations-within-the-same-table/75744/5 "2024-08-21T10:46:26Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [August 22, 2024, 12:01am UTC](https://community.glideapps.com/t/relations-within-the-same-table/75744/6 "2024-08-22T00:01:39Z")

</div>

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

> **[Forms | Glide Docs](https://www.glideapps.com/docs/forms)**
>
> Collect data from your users in customizable forms.

[![](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/d/a/da061a6127c1780ad2a69241a06d6acc04d3c0c3.jpeg "Learn How to Create Forms | Glide Apps Tutorial") ](https://www.youtube.com/watch?v=CafLVrv4g1s)

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.
