Define reverse relationship with Tailor

Hello,

When you use tailor to link one model (let’s imagine Blog\Post and Blog\Category), It’s quite easy to do, in my post blueprint, I have

categories:
    label: Catégories
    type: entries
    source: Blog\Category

so, using twig, I can easily access all categories associated to a post using {{ post.categories }}

But it seems that the reverse relation is not made automatically, so my question is, how can I access all posts associated to a categories ?

Tested this :

{% for category in collection %}
   {{ d(category.posts) }} // return null, I would like it to return the collection of all posts associated to that category.
{% endfor %}

Thank you

1 Like

We should be able to add support for this by defining the inverse relationship and optionally hiding the field. For example, something like this:

# Coming soon...
posts:
    type: entries
    # ...
    inverse: true # Inverse relation
    hidden: true # Hide form field (optional)

I have added this to the internal tracker for review. Thanks!

Hello,

Ahh, it would be a really nice addition. Thank you for your support.

Best regards,