Comparing two relations

Hi,

I built a social network app. Each user has “friends” (which are other profiles). I want to calculate mutual friends, or at least to note if two users have mutual friends at all.

Is there a way to compare two relations?

Thanks!

Was sort of thinking about comparing matching items between 2 different relations via another relation but I don’t think it’s currently possible.

@Yuval,

I know it would take you out of glide, but this could easily be done in sheets. If a solution in glide cannot be found.

Although there may be a small delay this is not something that the user is actively using and waiting for immediate results. I cannot imagine any lag introduced by doing this in sheets would affect the user experience.

Thanks, will consider it.

Perhaps @Jeff_Hager has a creative hack within glide :pray:?

@Yuval

How is your data structured?

I have a profiles sheet (I think rather a standard one).
Another sheet holds the friendship records. One column for User’s email, another column for Friend’s email (this sheet is filled with a form).
Then I do a relation from the friends sheet to the profile sheet, to bring together all the friends per user…

Ok. So if I have 10 friends my email shows up in 10 rows, then your email in the next 10 rows if you had 10 friends for example?

Yep, for example. Of course order of rows could mix as people add friends on various times, but I think you got the idea

I do not see how this could be done in glide. I have done it in sheets though. Pretty simple.

One thing I realized in creating the demo, you will need to add the inverse friend relation after someone adds a friend (either automatically or have the other user “approve” it and then have it added upon approval.

Without this the issue cannot be solved as the reference column is ill defined. AKA you need a column that is the match column for names and the next column has the friends.

So if Bill decides to be friends with Jim, two records need to be entered Bill | Jim and Jim | Bill, unless ofc your friendships are unidirectional.

Let me know if you are interested in the sheets solution.

2 Likes

I’m going to assume that you friendship sheet is always set up so the first column is the user profile, and the second column is the friend of that user.

  • First create a template that joins the first user id column to the second user id column in the friendship sheet.
  • Create another template column that joins the user id from the signed in user profile to the second user id column in the friendship sheet.
  • Create a relation column that links the second template column to the first template column. If a match is found, then that should indicate that a both users share a friend.
  • Now you can create an if/then column that checks if the relation is not empty then return ‘true’ or whatever value you want. If the relation is empty, then you can return false or blank. Whichever works for you. You could return an emoji, text, image or whatever you need to indicate that you both share a friend.
3 Likes

Thanks! I’ll try to implement Jef’s solution first, and will let you know

Brilliant!
Thanks a lot.
I think I’m just stuck with the last “if-then” phase.
The friends records are in a dedicated sheet, and every user can appear multiple times (every time he adds a friend, another record is created).
Using your logic, I succeeded bringing to the profiles sheet a relation with all the profiles (or emails) with whom each user share mutual friends.
But I don’t succeed in marking, per user, if I share a friend with him or not…

Could you share a couple screenshots that show how you ended up setting up the friendship sheet and and how you created the relation in the profile sheet?

Ok sorry, it’s working now. Thank you so much.
@Mark you should hire this guy (if you haven’t already) :heart_eyes:

4 Likes

Hehe, they wouldn’t be able to afford me. :wink:

1 Like

Na nobody can
ecspecially because of your quick brain :brain: :wink:

1 Like