<p>So, it looks as though I was overcomplicating things! All it needs to be is this:</p>

<pre><code>{% set exhibitors = craft.entries.section('exhibitors').order('title') %}

{% for exhibitor in exhibitors %}
    {% set room = entry.rooms.relatedTo(exhibitor).first() %} 

    {{ room }} &lt;-- No longer a null entry

{% endfor %}
</code></pre>

CC BY-SA 3.0
2015-07-24T13:04:25.143Z
2015-07-24T13:04:25.143Z
Steve Holland
<p>I'm having a little trouble wrapping my head around <a href="http://buildwithcraft.com/docs/relations" rel="nofollow">Relations</a> through a <a href="http://buildwithcraft.com/docs/matrix-fields" rel="nofollow">Matrix</a> field.</p>

<p>I have a <a href="http://buildwithcraft.com/docs/sections-and-entries#section-types" rel="nofollow">Structure</a> called <code>exhibitors</code>.</p>

<p>I have a Matrix field on a Page called <code>rooms</code>, This has one block type <code>room</code> and within that block there is an entries relationship field called <code>exhibitors</code>.</p>

<p>What I'm wanting to do is loop through the <code>exhibitor</code> entries and for each one, I want to find the first room they are related to via the matrix field.</p>

<p>I've tried various flavours of the <code>relatedTo</code> method, but I just can't seem to get them related, I just get null back from every one I've tried.</p>

<p>Here's an example of one I've tried:</p>

<pre><code>{% set exhibitors = craft.entries.section('exhibitors').order('title') %}

{% for exhibitor in exhibitors %}
    {% set room = entry.rooms.relatedTo({
        sourceElement: exhibitor,
        field: 'room.exhibitors'
    }).first() %}

{{ room }} &lt;-- Always a null entry

{% endfor %}
</code></pre>

<matrix><relations>
Relationship through Matrix field
# Relationship through Matrix field

(Asked by: username_0 on 2015-07-23)

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 %}

**Tags:** matrix, relations

---

## 1 answers

### Answer by username_0 on 2015-07-24. Score: 1 | Accepted answer

So, it looks as though I was overcomplicating things! All it needs to be is this:
{% set exhibitors = craft.entries.section('exhibitors').order('title') %}

{% for exhibitor in exhibitors %}
    {% set room = entry.rooms.relatedTo(exhibitor).first() %} 

    {{ room }} <-- No longer a null entry

{% endfor %}


---

