<p>This is untested code.</p>

<pre><code>{% set coachingTeam = craft.entries({
  section: "divisions",
  type: "team",
  relatedTo:[
    'and',
    { targetElement: currentUser.id },
    { targetElement: headCoach[0].id }
  ]
}) %}
</code></pre>

CC BY-SA 3.0
2015-01-12T08:00:39.947Z
2015-01-12T08:00:39.947Z
a-am
<p>I currently have a structure called 'Divisions' that includes 'Team' pages as children. On the 'Team', there is an entries field 'Head Coach', which is an entry created on a 'Coaches' channel.</p>

<p>The coach has an account and has created the entry, so he is the author.</p>

<p>My question is, assuming the coach is the 'currentUser' is there a way to find the relation between that 'Head Coach' entry and the 'Team' if they are related by the author?</p>

<p>I have this code so far:</p>

<p><code>{% set coachingTeam = craft.entries.section('divisions').type('team').relatedTo({
    targetElement: currentUser,
    field: 'headCoach'
}).find() %}
</code></p>

<p>The only way I've found to do this was to loop through all the teams, and if the currentUser and the author of the 'Head Coach' entry matched, then set the team.</p>

<p>It seems expensive, but I can't figure out how to do this with a relations call.</p>

<p><code>{% set allTeams = craft.entries.section('divisions').type('team').find() %}
{% set coachingTeam = '' %}
{% for team in allTeams %}
    {% if (team.headCoach|length and team.headCoach.first.author.id == currentUser.id) %}
        {% set coachingTeam = team %}
    {% endif %}
{% endfor %}
</code></p>

CC BY-SA 3.0
2015-01-12T07:51:01.297Z
Your trying to return a team that has the current user as the author and as the Head Coach?
a-am
CC BY-SA 3.0
2015-01-12T19:48:51.937Z
I'm trying to return the team that has the currentUser as the author of the 'Head Coach' entry that is attached to it.
aj1215
<entries><relations><search><entries-field><author>
Getting relation through entry field by author
# Getting relation through entry field by author

(Asked by: username_0 on 2015-01-11)

I currently have a structure called 'Divisions' that includes 'Team' pages as children. On the 'Team', there is an entries field 'Head Coach', which is an entry created on a 'Coaches' channel.

The coach has an account and has created the entry, so he is the author.

My question is, assuming the coach is the 'currentUser' is there a way to find the relation between that 'Head Coach' entry and the 'Team' if they are related by the author?

I have this code so far:

`{% set coachingTeam = craft.entries.section('divisions').type('team').relatedTo({
targetElement: currentUser,
field: 'headCoach'
}).find() %}`

The only way I've found to do this was to loop through all the teams, and if the currentUser and the author of the 'Head Coach' entry matched, then set the team.

It seems expensive, but I can't figure out how to do this with a relations call.

`{% set allTeams = craft.entries.section('divisions').type('team').find() %}
{% set coachingTeam = '' %}
{% for team in allTeams %}
{% if (team.headCoach|length and team.headCoach.first.author.id == currentUser.id) %}
{% set coachingTeam = team %}
{% endif %}
{% endfor %}`

**Tags:** entries, relations, search, entries-field, author
> **Comments:**
> **username_1**: Your trying to return a team that has the current user as the author and as the Head Coach?  
> **username_0**: I'm trying to return the team that has the currentUser as the author of the 'Head Coach' entry that is attached to it.  

---

## 1 answers

### Answer by username_1 on 2015-01-12. Score: 1

This is untested code.
{% set coachingTeam = craft.entries({
  section: "divisions",
  type: "team",
  relatedTo:[
    'and',
    { targetElement: currentUser.id },
    { targetElement: headCoach[0].id }
  ]
}) %}


---

