Create a relation with the same collection type using the same field name

System Information
  • Strapi Version: 3.1.4
  • Operating System: MacOS
  • Database: MongoDB
  • Node Version: 12.18.2
  • NPM Version: 6.14.8
  • Yarn Version:

Hi,

I’m trying to set up a relation of a collection type (Articles) with the same collection type (Articles). I would like to have the articles relation name but if I use the same name on both ends of the relation, it will say that “This value is already used.“. Does anyone know how to achieve this or if it’s possible?

Please note that I need to have the same field on boths sides of the relation, not different ones (I know that’s possible). Also the relation needs to be visible on sides, not “has many” won’t work either.

Just in case, I also posted it on github

Thanks

hey man can u explain what do u want to do with ur collection type ? i dont understand why should u want to relation articles with articles . example i want a collection type resturant with it has and belongs to many food .

I think he wants to make something like RELATED articles.

1 Like

That’s exactly what I’m trying to achieve, related_articles! I need a bidirectional relation, so all related articles are under the same field related_articles on both articles.

I don’t know if this is possible with bidirectional relation. Never tried it.

But I can recommend you another flow that I used, create a collectionType called Tags and create multiple tags there, like: health, travel, money, relationship, etc.

Add all related tags to your articles and in frontend get only the articles with similar tags. That way you will get more “intuitive” related articles.

In this case, the client will want specifically to relate certain articles with others. I don’t think tags will work, unfortunately.

I just can’t believe this is not achievable. And I will have this same issue with other collection types as I need to have the same scenario with others.

Do you know if this will be developed at some point or where I should raise this?

well if it was me i would create a collection type named article categories
relate it with my articles or
a repeatable component with tags . then would create a dynamic page in my frontend for the selected tag that if someone klick a tag it would filter the articles with that tag

1 Like

I already have a Article categories collection type which is different from a Related articles relation. I simply need to have a collection type related with itself, in more than one scenario. Does that mean it’s not possible?

Well I just had the same issue as you (collection type Project should have a relation with the collection Project ), my answer surely come to late but maybe it will help some others.

To resolve that I had to create a simple component with a single field, and this field embed the needed relation.

I works perfectly for me,
Hope it will for you… or anyone else :wink:

7 Likes

That was helpful. Using a component with a single relation field makes it very easy to load related records of the same content type

That is helpful to me but i want that user can only select 3 related articles not more than that you know how could i set the limit for this relation ??

I did implement as per your solution. But the related ID is showing only the same ID as of the row and not the related IDs. Can anyone help me on this?

Thank you