Save relation items order (Issue #2166)

Just here to find out the current status the conversation on this. There is an issue open on the github kanban board, but that is only linked to a closed PR that is for v3.

Sorted relationships are table stakes/must haves for many applications, as seen in this thread and in the related github topic for sortable collections. Ordering Content Type entries in the List view (preferably using drag and drop) ¡ Issue #3946 ¡ strapi/strapi ¡ GitHub

Most of the assumptions made in this thread are spurious and mis-informed. What REST APIs allow content to be manually sorted? Playlists for one. (Youtube, Spotify) How do you update hundreds of rows in order “to move item 874 to position 4, that’s 870 entries that have to have their order adjusted and it needs to happen fast.”

UPDATE table set sort_order = sort_order + 1 where sort_order >=4 and sort_order<875;
UPDATE table set sort_order = 4 where id = <moved_item_id>;

I haven’t looked at how this works under the hood in SQL, but typically this is done with a new table in between. Playlists → Playlist_songs → Songs.
At Spotify I don’t want any users to edit song content, but I want users to add the link to the song to their playlist and reorder.

This is just so so basic. It’s sad to see that the product team has not considered this even as the product reaches v4.

It doesn’t seem as if Bookshelf.js prioritizes or includes/allows for any metadata around the relationship.
Here is a description of how Django handles it.
https://docs.djangoproject.com/en/4.0/topics/db/models/#extra-fields-on-many-to-many-relationships

I was pretty surprised to find this feature lacking in Strapi! I was looking for exactly what @JohnRomanski suggested, adding fields to the relationship ‘join table’. This is the common way to handle this in SQL, and has been supported by some CMS’s for many years… I remember first encountering it in SilverStripe over a decade ago.

@jorisw that worked great! Do you know if it’s possible to update the component through a REST API PUT request? Or only through the admin view?

No idea. I would expect so. Surely one of the Strapi people in this thread could tell you?

In the 4 years that I’ve been around Strapi and all of the other platforms I’ve looked at (Wordpress included) I have never seen a viable reason to manually order content.

Then you haven’t been around enough. We have this exact need. We do e-learning courses and digital textbooks. This is a very common requirement for linear course-type content applications.

For the courses, there are multiple lessons that are being maintained. Many of the lessons are reused in other courses (many-to-many), so a simple field with “lesson order” doesn’t work, because a lesson might be ordered in a specific position for one course and be ordered in a completely different position in another course. Plus, some courses have over a hundred lessons. Imagine having to re-order all of those manually when you want to add a new lesson in between two others, or simply re-order them. As we continually update course versions, this is done daily.

Furthermore, each lesson has multiple “slides.” Same issue with these.

And where Strapi really breaks down for us is using it for linear, digital textbook content. We have units, sections, chapters, and pages; and are continually adding and re-ordering them. Some books have hundreds of pages of content.

Strapi simply doesn’t have the functionality we need for the content structure we require and is not useful for e-learning applications that require linear course-type content structures. We’d have to build an intermediary application to handle this and that would introduce a whole new set of challenges, but thankfully other platforms support this. So we are using one of their competitors. Our developers preferred Strapi during the evaluation process, but the lack of ability for our teachers to easily re-order collections of content related to others was a deal killer for us.

2 Likes

We power an ecommerce site where we have the same need for different orders in different collections. We were really hoping strapi v4 will sort this as promised but it seems like it didn’t. Which competitor did you go for?

Anyone here found a solution?

Recently I came through this issue and decided to create a repeatable component that contains only one relation to the collection.

The list of repeat table is stored in orders so we have extra fields in the API response but instead we can have an ordered list of relations ( data inside the collection type can be populated successfully using populate query )

Just my little help!

Unfortunately no. I just assumed this would be in there since every CMS has it in either their core or via a plugin everyone installs. Wordpress/ExpressionEngine/Craft/Drupal - you name it.

I read a note from earlier from the Strapi team where they said that this likely won’t be a feature anytime soon. I hope I’m wrong. The quote was that they’re focused on developers and not content creators which just doesn’t work for real world scenarios. A CMS in the end is for content creators/marketing directors/etc, not developers. It’s why CMS’s exist. Changing the order of products on the homepage should not require a client to call us. That’s the CMS’s job. Will check back on Strapi from time to time as it’s maturing, but this is just a non-starter for us.

1 Like

Apologize in advance if my note came off as snarky. I only cared to write that note because I see the potential of Strapi. I have yet to find a good, solid, polished Node based CMS out there and I think Strapi is right on the cusp of gaining a mass market following. Just need to get these little things right and we’d be moving over to it full time.

Great job to the devs on v4. Just need these little polishes before we jump off the PHP ship. And trust us - we want to jump off the PHP ship.

I heartily support adding this feature as well. We have a “Pages” collection type, which links to a “Sections” collection type. The ability to reorder the sections on a page is critical, since most pages are used for marketing and must take users through a logical content flow. The sections on each page also change every few months, with our marketing team adding new sections and removing old ones. The inability to specify the order of these sections after the initial page creation has me seriously questioning using Strapi moving forward.

2 Likes

I just built the exact same thing and found out the sort isn’t working :disappointed_relieved:

1 Like

I agree! After a long migrating to v4 I realized that many things not work anymore… next to the broken relations like user role, I also noticed that sorting of relations is also broken. So I am also at the point to thinking about to stop using strapi…

5 Likes

Ok so I have found a couple of ways around this. None are optimal but can work.

First approach is to create a repeatable component that takes 1 relation to a collection. You can then reorder this component to whatever suits. The problem with this is that you often run into problems with deep nesting.
Using graphQL seems to help prevent some issues with deep nesting.

Second is if you delete all items in the relation field, and add them back in again in the correct order, it should maintain the order. However this means if you want to add a new one in the second position, you need to delete all items from the list, and add them back in again. This is also just kinda flaky.

Lastly you can add a field to sort by. I actually haven’t tested this, as at that point I usually query & filter the whole collection type, rather than using the relationship field.

Hope this helps someone, but I agree it would be really convenient to be able to reorder a multi relationship field.

1 Like

The ability to change the order of items is essentially for users.

As a developer, you can find a lot of workarounds i.e. adding custom fields, plugins, deleting and reinserting items …etc.

But the user needs to be able to just drag and drop the item up or down to get a new order of items.

That’s not depends on headless or monolith architecture of CMS.
If it’s CMS and end-user works with it directly, it should respect User Experience (not developer).

Actually, easy reordering of items (especially media) through the admin GUI is a key feature in case of choosing CMS for new project.

2 Likes

We have recently implemented our new site using Strapi - a fairly typical SaaS type site where we feature use cases and clients and we want to be able to manually determine the order that use cases are presented at various places in the site, to reflect those that are most valuable within the context.

The developer who built the Strapi implementation used relations - make sense we have use case entities and we have pages where they need to appear and there is a many to one relation.

Then as the thread above reflects, there is no way for content creators to order these use cases other than manually deleting them all and then readding them in the target sequence, which when you’ve got a dozen or more entities is crazy tedious when even the most of UX would just allow someone to drag them into order.

I think it’s extremely arrogant to assume that this is not a core use case for a CMS when weighting relationships is a common requirement. At the moment I feel as though we made a bad decision to go with Strapi.

PS: Lack of 2FA or any brute force protection on admin logins was an unpleasant shock but that’s a whole other story.

1 Like

Strapi v4.5 (currently in beta) will lay the foundation for sortable relations. From my interpretation even though v4.5 will not support sortable relations, it enables the core Strapi devs to work on that for a possible v4.6 release.

Source:

Last I spoke with the product manager for our content squad (the squad working on the relations stuff), I think we actually will get order-able relations in v4.5, -I think-

Based on some of the PRs the team is working on:

2 Likes

Not in 4.5 but it’s coming :slight_smile:

1 Like

Currently in beta testing now (along with our DEITS feature) feel free to test out with v4.6.0-beta.1 :slight_smile: