1

Is ist possible to "concatenate" entries?

For example:

  • You have five articles (A, B, C, D, E) ... might be a blog
  • Editing the article A: A is related to C and D
  • The relation should work bidirectional: Articels C and D know their relation to A automatically ... some kind of "this article got a relationship from article A"

The idea behind: You have not to edit all three articles.

My question is concerning the control panel, not just the templates.

2 Answers 2

2

The native entries field in Craft doesn't support this. The entries field always has a source and a target entry, and in the Control Panel, you only see the related entries in the source entry. For bidirectional relations that are also visible in the Control Panel, you can use the Reverse Relations plugin.

However, you might not need this. Under the hood, all relations are stored in a junction table, and you can query for related entries regardless of direction:

{% set relatedArticles = craft.entries()
    .section('articles')
    .relatedTo({ element: entry, field: 'relatedArticles', })
    .all()
%}

This will give you a list of all articles that are related to the current entry through the relatedArticles field, regardless of which one is the target and source element. You only need the plugin above if you absolutely need those bidirectional relations to be visible in both entries in the Control Panel.

1
  • 1
    Whow ... this answer is gold worth ... thank you so much, Moritz!
    – Marc
    Aug 1, 2023 at 14:35
1

The solution from Moritz seems to work.

I suggest to set the Reverse Plugin Field to read-only. This should reduce the complexibility for the editor in the control panel.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.