Many to Many Relationships in Bubble

Hi,

I’m struggling a bit trying to display items in a repeating group. I have posts with a list of tiers and a list of tiers for each user. I need it to display only the posts where the user has any corresponding tier.

Group 1 is the post tiers and Group 2 is the user tiers. Basically need something like a condition that says “one of(any), is in”, but that does not exist.

How do you solve this without making tons of duplicate data?

oneofisin

Hi @marcuslate :slight_smile: You can check to see if the same item is within both lists by using the expression:

Post's List of Items intersect with User's List of Items: count is not 0
(This means that there is at least one Item that is the same within both lists)

To display the Item(s) that are the same within both lists the expression would just be:
Post's List of Items intersect with User's List of Items
(This evaluates to a list of Items)

And to see how many Items are the same in both lists, the expression would be:
Post's List of Items intersect with User's List of Items:count
(This will evaluate to the number of Items that are the same within both lists)

That should do it! Feel free to let me know if you have any questions! :slight_smile:

6 Likes

Thanks for the answer @fayewatson :slight_smile:

I don’t see how I can display the right posts though. Since I need the made up “one of(any), is in” expression, instead of “contains”. Since contains does not take lists.

1 Like

I did make it work by adding users as a field on the tier. Then I used an advanced filter to get the right posts. I will mark this as solved but if anyone has another idea I’m open to hear it.

No problem at all! :slight_smile: Can you share a screenshot of the query you have with the advanced filter?

Any idea how to exclude the items that are the same in both lists?

@dserber I’m not sure of a way to do this client side, but you could do this using two “Make Changes to a Thing” actions to obtain that list. For example, let’s say you have three “List” things (List 1, List 2, and List 3), and each List has an “Items” field (type: Item, list: yes).

To see which Items are not the same in List 1 and List 2 (i.e., exclude the same items in both lists), you can first set the value of List 3's list of Items to be List 1's list of Items merged with List 2's list of Items:

Then in the second action, remove the items that are the same in List 1's list of Items and List 2's list of Items from List 3's list of Items using “remove list” (list to remove: List 1's list of Items intersects with List 2's list of Items):

This way, List 3 would contain all of the Items which are found only in either List 1 or List 2, but not Items that are found in both List 1 or List 2. I think that should work, but let me know if not! :slight_smile:

2 Likes

Thanks @fayewatson! That worked. It would be nice to have a way to do this client side as well. Seems like a missing feature.

1 Like

No problem at all! :slight_smile: And I totally agree; it would be very helpful to have!

1 Like

Sure, here it is.

@marcuslate Thanks! :slight_smile: Are there any constraints in the “Do a Search for” part of expression?

Are you looking to compare a list of Posts and the Current User’s list of Posts, to find the Posts that are found in both lists?

@fayewatson Yes I do, I have a list of users on every user, the users in the list are the creators of the tiers that the user is a member of, I think this speeds up the search.

image

I’m finding posts that has tiers that the current user is a member of. Find and match.

@marcuslate So sorry for the delay in responding! Are you storing a list of Posts on any other type? Or the Post data type contains a list of Rewards Tiers, and a list of Members?

@fayewatson The post contains a list of tiers and each tier has a list of members.

@fayewatson With this setup as M:M, I’m wondering if there is an easy way to remove an association.

For example, I have a table for User and Topic. User has a List of Topics, Topic has a List of Users. I can easily set up the workflow to add a User to a Topic’s List of Users. However, there is a use case for a User editing their List of Topics.

When a User deletes a Topic from their List of Topics, what would that workflow entail? Would I need to compare the User’s existing List of Topics with their newly edited List of Topics to target the Topic that was removed? Or is there an easier way?