1

I am using the Many to Many plugin and wondering if the below is possible.

I have a channel called Model ID. Model ID is then related to two other sections, Memory and SSD. I want to be able to link entries from Memory to entries in SSD via the Many To Many Field within Model ID.

Below is a picture, edited, to show the field layout and the information I have within the Model ID entry. The information within the entry is what I need to pull in to my Memory and SSD section but can not figure it out.

I feel like I am missing something very simple that might not be in the read me document for the plugin.

Any help would be appreciated.

Thanks John

enter image description here

  • Your issue can't be solved by this code? github.com/page-8/craft-manytomany/blob/master/… you can use this field like every other relation field in Craft. – Robin Schambach Jun 26 '18 at 15:50
  • The code there works just fine but links me to the Model ID, not to Memory or SSD section. I really feel like its an easy solution that I am not just understanding or seeing via templating. – jhoysa Jun 26 '18 at 16:10
  • Uhm.. So you didn't try to just grab the field value and query for the related elements {% set ssd = entry.fieldHandle.all() %} replace fieldHandle with the handle of the specific field. It will return an array of elements. Is that what you are looking for? – Robin Schambach Jun 26 '18 at 16:12
  • I am trying this but no luck - {% set modelIDs = entry.memoryModelIds %} {% for modelID in modelIDs.all() %} {% set ssd = modelID.relationshipsSsd.all() %} {% for product in ssd%} {{ product.title }} - {{ product.url }} {% endfor %} {% endfor %} – jhoysa Jun 26 '18 at 16:22
  • I am currently in the Memory section trying to access information from the Model ID section. Here is the code I use to pull in the Model ID title: {% set modelIDs = entry.memoryModelIds %} {% for modelID in modelIDs.all() %} <li>{{ modelID.title }}</li> {% endfor %} – jhoysa Jun 26 '18 at 16:26
1

So, if I understand you correctly, you're trying to use the Model IDs channel as a middle man? If so, I think you would just need two steps:

To get all SSDs from a Memory Entry

{% set modelIDs = craft.entries.section('MODEL ID SECTION HANDLE').relatedTo(entry).ids() %}
{% set ssds     = craft.entries.section('SSDS SECTION HANDLE').relatedTo(modelIDs).all() %}

To get all Memory from an SSD Entry

{% set modelIDs = craft.entries.section('MODEL ID SECTION HANDLE').relatedTo(entry).ids() %}
{% set memory   = craft.entries.section('MEMORY SECTION HANDLE').relatedTo(modelIDs).all() %}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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