robuust / craft-reverserelations

Reverse Relations for Craft
MIT License
12 stars 15 forks source link

[Q] is there an example available #17

Closed therealpecus closed 4 years ago

therealpecus commented 4 years ago

Hello,

I'm looking for minimal information as to how to use the plugins when setting fields in craft. What I am trying to achieve:

What is the field setup needed to achieve this scenario? Once I get a handle of how the plugin works i can contribute a tutorial or extended README

thanks!

therealpecus commented 4 years ago

never mind, I figured it out. I'll close this.

ben-at-sahmri commented 3 years ago

Hi @therealpecus - any chance you could share your wisdom here? I'm pretty new to Craft (and rusty at PHP), so I'm having trouble intuiting how to use this. Thanks!

therealpecus commented 3 years ago

The reverse relation plugin allows you to construct a bidirectional reference between a field and ENTRY fields. Let's say you have a section with entries that describe products (sectionProducts) and a section with entries that describe family of products (sectionProductFamilies). You want to be able to see the product family from the product, and the child products from the product family.

Here's how you would do it:

Now, when you edit a productFamily entry in the control panel, you'll choose the products (as entries) that belong to it through the productsOfThisFamily field. When you edit or display a product, you'll see the product family/ies it belongs to in the productFamily field. If you did not check the read-only field, you can also edit them from within the product itself.

ben-at-sahmri commented 3 years ago

Thanks so much @therealpecus - that's hugely helpful.

A follow-up question for you - does it matter which 'direction' the initial entry field is pointing? That is, do you need to define the child collection field on the parent as in your example, then reverse-relations reverses it to give you a parent field on each child? Or can it go the other way, too: set the parent field on the child and then reverse-relations gives you a children collection on the parent?

Update - works in both directions, thank you! I'll submit a PR to include a summary of this info to the README if you don't mind me stealing your work?

Thanks again!