How Post Relationship Replaces Post Reference and Repeating Fields
The next major feature for Toolset is “many to many relationship”. In this post, I want to introduce what’s planned and show what you can achieve with it.
What one-to-many and many-to-many relationships are
One-to-many means that one object “has” many other objects, or that many objects “belong” to one object. For example, a “project” may have many “revisions”. All revisions belong to a project. A revision cannot belong to two projects.
Many-to-many means that items of one side can connect to many items of the other side. For example, look at “events” and “speakers”. An event has many speakers and each speaker can appear in many events. In many-to-many relationship, there is no meaning to “belongs”, because each item can connect to many other items.
How post relationship replaces “post reference” and “repeating” fields
The most popular feature requests for Types have always been “post reference fields” and “repeating fields groups”. We’ve been a little hesitant to add these fields because it would make displaying content with Views a real pain. The “repeating field groups” in ACF, for example, use serialized data. This is super problematic for filtering purposes. In order to run a search over field values, you’d need to first de-serialize the fields and then search in PHP. Obviously, for a site that has more than a few hundred posts, this would be impossibly slow.
We checked a little (really, a lot) and understood that almost always, when you use post reference fields and repeating field groups, you’re creating some sort of relationship. For example, if you have a CPT called “flights” and you create a “post reference” field to save “landing airport ID”, you’re actually setting up an implicit relationship.
When you create a “house” CPT and use a repeating fields group for “photos”, you’re implicitly defining a new type “photos”, setting up its fields and connecting it to “house”.
Once you declare that “a house has photos” and “photos have XYZ fields”, you’re making it possible to:
- Add photos to houses
- Display the photos of a house when displaying a house
- Display the house when displaying a photo
But all of this is only possible once you declare the relationship. This is why using “field reference” fields without declaring what they do is so problematic for building sites without PHP.
Toolset 2.3 will make “field tables” look and feel exactly like “repeating fields”
So, we understand that post relationship actually lets you achieve the same thing as “post reference” and “repeating fields groups”. But you know very well that the post relationship in Toolset, so far, is much less convenient to use than the repeater fields in ACF. That’s correct and we’re finally fixing it for good.
In Toolset 2.3, you will enjoy a streamlined workflow that lets you:
- Add a “repeating fields group” directly
- Add a “post reference” field directly
In the GUI, you will not see the need to set up the post relationship. Types will understand that when you add a “post reference” field you’re telling Types that this post has a parent. And when you create a “repeating fields group”, you’re actually setting up a child type and its fields.
All this will happen in the background, without any delay to your work and without any additional load on the database. True, there will be an entry in the ‘posts’ table for every row that you add in a repeating fields group. This entry is insignificant compared to the huge saving you’ll get when querying for these
How post-relationship will be stored in the database
Toolset will create a new table for the post relationship. This table will hold both ‘one to many’ and ‘many to many’ relationships.
The benefit of using a custom table is performance. Before version 2.3, getting the list of all related items in a many-to-many relationship would take order-N queries (one query per item). In Toolset 2.3, this would take only a single query.
It’s not just the DB queries. Having the relationship stored in its own table will make the PHP a ton simpler and your designs much simpler too. You will be able to just say “get me all the songs by an artist” (which are connected as many-to-many) and you can create a simple View to display them.
Detailed design, GUI and release schedule
We have a team of 5 developers working full time on many-to-many relationship in Toolset now. Our aim is to complete the detailed designs and GUI mockups during September. Then, around November we should offer the first working versions. This is a very large project, so changes can happen. In any case, it’s the major upcoming development in Toolset and we hope very much that you’ll like it.
What do you think? How would you use post relationship? Which features are most important for you? Leave your comments and we’ll get back to you.