How relationships work in glide apps

Hello,

I am quite confused on how relationships can be used/applied properly in different components and in different situations.

Is there some instructional material that you would recommend for me to go over to be able to understand this?

Please.

I have watched the instructional material offered at glide but I still do not get it :confused:

Thank you.

1 Like

Hi! Iā€™d love to explain. I didnā€™t get relations either at first.


Imagine youā€™re building a social media app - an Instagram app.
Users can

  • Post
  • Comment

How do you make sure that each comment belongs to that post? How do you make sure it doesnā€™t belong to another post?

The answer?

Relations.

Letā€™s talk about how to setup a relation - a relation needs a specific value to relate to - it needs for something to match a value in another sheet - or in the same sheet, if you prefer. That might sound confusing at first, but keep reading.
When a user writes a comment, it opens up a form, right? And that form is where they can add the text that the comment contains.

So hereā€™s how to add a relation. First of all, add a new column to your ā€˜Repliesā€™ worksheet. It should be called ā€˜Post replying toā€™. Next, add another text entry pointing to ā€˜Post replying toā€™ that should only be visible when the post title is [garbage text]. Yes, I know the post title is never going to match whatever garbage text you inserted, but thatā€™s the point! Youā€™ll see why in a second - you donā€™t want to give the user the ability to edit the post itā€™s replying to! Next, make the default value the title of the post. In summary, what you just did is make an entry invisible so that users canā€™t see or edit it.

Next, you want to set up your relation. Go to the Glide Data Editor, and click new column. Then, set the column type as ā€˜Relationā€™. Hereā€™s the setup: Choose that the ā€˜Replying toā€™ column matches the value in ā€˜Posts>Titleā€™. Do not select ā€˜Match Multipleā€™.

You can now add a relation component to your reply layout, so that when clicked, it will bring you to the post itā€™s replying to.

We did singular relations. Now letā€™s focus on Multiple Relations.
For clarification: Singular Relations let you refer something to ONE value in another sheet. Multiple Relations lets you refer something to MANY values in another sheet. We just made it so that when a user clicks the relation component in the comment, it will bring them to the post. But now itā€™s time for the most important thing. How do you list the Replies in your post? For that we need to refer something to MANY values in another sheet - thereā€™s not going to be a maximum of 1 comment!

This part is easier, because you already did the singular relation before. Add a Relation in the GDE in the ā€˜Postsā€™ sheet and Make is so that ā€˜Post Titleā€™ refers to ā€˜Comment replying toā€™ in the Comments sheet. Donā€™t forget to make it a Multiple Relation by selecting that checkbox!

Now, what you can do is list the replies in your post - the source should be the relation.


I really hope this helped you a bit more. Also, are you just experimenting with Relations or just experimenting? If you still donā€™t get it Iā€™d be glad to make a copyable app.

All my best!
Pablo

3 Likes

Can you make a shareable app to demo please. thanks

Here ya go

2 Likes

That is great. Can you make it shareable.

Sharable? Not sure what that means. The about screen is enabled

1 Like

I mean that I can copy. thanks.

Done

2 Likes

Awesome @pablo_books
Thanks

1 Like

No problem. DM me if you need help with something!

1 Like

Thank you so much for the help :)! It is much appreciated.

Do relationships have some type of expected behavior?
For example, it always ā€œgrabsā€ information from the column next to it, be its right or left side?
How do relationships ā€œchooseā€ which items will use to fill its column?

As if a relationship creates a ā€œdoorā€ that connects two ā€œroomsā€ (sheets) inside a ā€œhomeā€ (spreadsheet). I wonder what items the relationship is expected to bring from the other room and how this is chosen (if its chosen at all or may be random).

I am not sure that this would even matter because I have seen lookups bringing specific desired data using a relationship to connect to a certain sheet. I just wonder if there is an expected behavior.

Iā€™m not sure how it chooses which column value to display in a relation column. It used to always be the first column in the linked sheet. Regardless it doesnā€™t really matter. It just tells you that it found something. Relations link to entire rows, so whichever column it shows is irrelevant. Relations are like a mini version of a sheet inside of a sheet that you can use for lists, or you can use a lookup, single value, rollup, etc. columns to pull specific columns or values it of that relation.

4 Likes

oh manā€¦ I have spent hours staring at printed sheets (of different apps), placed them next to each other trying to catch ā€œthe patternā€ that relationships ā€œsupposedly haveā€ (according to me). And all this time, this may have been a random behavior, there was nothing to ā€œfindā€ā€¦ and there I was immersed into a hole of self-made confusion. XD
I apologize about it, I sometimes love to make a problem out of nothing. Just wow XD.

3 Likes