Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-12T08:00:39.947Z
Answers.LastActivityDate: 2015-01-12T08:00:39.947Z
Answers.UserDisplayName: a-am
Body: <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>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-01-12T07:51:01.297Z
Comments.Text: Your trying to return a team that has the current user as the author and as the Head Coach?
Comments.UserDisplayName: a-am
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-01-12T19:48:51.937Z
Comments.Text: I'm trying to return the team that has the currentUser as the author of the 'Head Coach' entry that is attached to it.
Comments.UserDisplayName: aj1215
Tags: <entries><relations><search><entries-field><author>
Title: Getting relation through entry field by author
ThreadText: # 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 }
    ]
  }) %}
  
  ```
  
  
  ---
  
  