8

So, for example:

Say I have two sections:

- Recipes
- Ingredients

Recipes can have many ingredients. Ingredients can have many recipes.

If I'm editing a Recipe, I can edit the ingredients. This updates the relationship so that when I edit ingredients it can show the associated recipes (and they are editable from the ingredients as well).

Is this possible with Craft?

Thanks!

====== EDIT ======

Just to make this more clear. What I'm trying to do is create a Many to Many relationship between two Sections of Entries so there is an association between the two that works both ways.

Another example of this would be if you have a User with many Roles. I can manage which Users belong to which Roles from the Roles section, and/or I could manage which Roles a User belongs to from the Users section.

2 Answers 2

7

There's still a few kinks to work out, but I developed a plugin that solves this problem using Craft's native Many to Many relationship that already exists.

Basically, I've created a field type that links the relationship from the other side of things and allows you to add entries to it.

You can find it here: https://github.com/page-8/craft-manytomany

Thanks @Brandon Kelly for the help and guidance.

2
  • 2
    Great Peter, nice work! Go ahead and submit that to Straight Up Craft, if you haven't already... I'm sure others would find it useful as well! :)
    – Lindsey D
    Jul 12, 2014 at 23:34
  • 1
    Good call Lindsey. Done and done.
    – Peter Tell
    Jul 13, 2014 at 1:14
6

You can assign ingredients to recipes using the built-in Entries field type.

Then, to view which recipes an ingredient is used on, check out the Introvert plugin. It gives you a new field type that can be used to simply show reverse relationships, also providing links to edit those other entries.

2
  • Thanks for the Response Brandon. This is about half way there. The client has requested the editing be a two way street, meaning that they be able to add and remove associated recipes from the ingredients edit screen. This is beneficial because say they were to add a new ingredient, they can quickly associate it with all applicable recipes rather than having to open each individual recipe and add it there.
    – Peter Tell
    Jul 1, 2014 at 22:13
  • 1
    Ah, yeah. Currently that’s not possible with Introvert. Feature request! Jul 1, 2014 at 22:16

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.