php - Directus : How to create a many-to-many relationship to the same collection properly

one text

Solution:

There seems to be a discrepancy in the description as I can understand, but, is this what you are trying to do:

topics.related_topics => junction collection => topics.id

If so, you have created a unidirectional relation from parent to one or more children on the field related_topics, in that you are asking what topics are related to this item.

If you want to see to what parents a child item is related, create another M2M Interface using the same junction collection, but flip the fields from the previous M2M Interface settings and now you can see it the other way automatically.

You should then be doing:

topics.id => junction collection => topics.related_topics

The logic of M2M is unidirectional: parent to many children as it extends O2M: https://docs.directus.io/guides/interfaces.html#core-interfaces

You can, however, extend the M2M Interface if you want to make it bidirectional by following, intermediate understanding of Vue.js is recommended: https://docs.directus.io/extensions/interfaces.html

You would need to update the input.vue in: https://github.com/directus/app/tree/master/src/interfaces/many-to-many

Source