I'm having a little trouble wrapping my head around Relations through a Matrix field.
I have a Structure called exhibitors
.
I have a Matrix field on a Page called rooms
, This has one block type room
and within that block there is an entries relationship field called exhibitors
.
What I'm wanting to do is loop through the exhibitor
entries and for each one, I want to find the first room they are related to via the matrix field.
I've tried various flavours of the relatedTo
method, but I just can't seem to get them related, I just get null back from every one I've tried.
Here's an example of one I've tried:
{% set exhibitors = craft.entries.section('exhibitors').order('title') %}
{% for exhibitor in exhibitors %}
{% set room = entry.rooms.relatedTo({
sourceElement: exhibitor,
field: 'room.exhibitors'
}).first() %}
{{ room }} <-- Always a null entry
{% endfor %}