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