I’ve been tinkering with Webflow CMS to see if it’s suitable for a project I have in mind. I can’t seem to figure out how to implement what traditionally would be referred to as a many-to-many relationship between database tables.
Let’s say, for instance, I want to have members and interest groups. A group can contain many members, and a given member could be in more than one group (have more than one interest). I might then want to display only members in a particular interest group. How would I go about setting up such a relationship and filter in Webflow CMS? I’ve tried to no avail.
Any assistance would be greatly appreciated.
Hey @Shotster, the closest you can currently get is what we call a Multi-Reference field. For example, here I’ll create a
Members Multi-Reference field on the
Interest Groups collection:
Once I have that data as part of each interest group, I can list out the members using a Dynamic List on the (and this part is important) Interest Group Template page. Once you’re on the template page, you can use the
Members field as a data source for the Dynamic List:
It’s not exactly a many-to-many relationship, because it’s a one-way connection. That is, the
Members collection doesn’t have a corresponding
Interest Groups field that is kept in sync - so if you wanted to list out “the interest groups this person is a member of” on the Members Template page, you’d have to create a separate Multi-Reference field on the
Members collection (linking to the
Interest Group collection), and enter the groups for each person.
This means that the synchronization between the two is a manual process (for now), but it also means you have some added flexibility to manage the data relationship from both sides.
Thanks very much for the prompt reply, @callmevlad!
Unfortunately, what you describe as flexibility seems to me to be unnecessary work. I would indeed want to list groups per member as well as vice versa. It’s unclear to me what benefit there would be to manually managing two separate one-to-many relationships every time a member joins or leaves a group.
I did try a separate “cross reference” collection which had two Reference type fields - one for members and one for groups. That’s similar to the way it would be done traditionally. However, there’s no way to “look up” or pull data from the referenced collections.
Many-to-many relationships are very commonplace in the real world, and WF’s lack of support for them, unfortunately, precludes its use for projects I have in mind. Another example would be photographers and photo albums. Let’s say a photographer can create albums for categorizing their work. An album can, of course, contain many images, and an image should be able to reside in more than one album - e.g. a bee on a flower might be in both the Insects and Flowers album.
Unless support for this is right around the corner, WF just won’t work for my projects. I was willing to try to proceed with the lack of support for mobile-first development, but a lack of many-to-many relationships is a real deal breaker.
Or is there? Maybe there’s some functionality I haven’t yet discovered?
I tried the same with a separate data collection to cross reference my movie data collections. didn’t work.
i have a data collection for movies and countries. each movie can have multiple countries and each country can have multiple movies.
meanwhile i “solved” my problem by back referencing the countries to the movies.
but as you said, you have to do everything twice.
but there should be something coming: Ability to Use More Than 3 References in a Collection - #29 by AlanBorger - Product feedback - Forum | Webflow