Answers.Body: <p>You should read the docs about <a href="https://docs.craftcms.com/v3/relations.html#the-relatedto-parameter" rel="nofollow noreferrer">relations</a> </p>
  
  <pre><code>relatedEntries = craft.entries.relatedTo({targetElement: currentUser, field: 'docsApprovedBy'}).all()
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-27T18:14:28.113Z
Answers.Text: That's still doing an additional query which I was trying to avoid. I already have the entry. I was hoping for something like 'if user.id in entry.docsApprovedBy'. Thanks anyway.
Answers.UserDisplayName: Amanda Lutz
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-27T18:16:20.547Z
Answers.Text: Then you can do `if currentUser.id in entry.field.ids()` but you can't do it without an additional query.
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-28T14:52:24.833Z
Answers.Text: Love it! Since I already have entry this is exactly what i wanted! Thanks
Answers.UserDisplayName: Amanda Lutz
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-27T14:58:48.097Z
Answers.LastActivityDate: 2018-07-27T14:58:48.097Z
Answers.UserDisplayName: Robin Schambach
Body: <p>This project has a lot of user stuff. I need to display display different sections based on if the current user is in a field.</p>
  
  <p>Is there a better/faster way than looping through and checking if every user matched the current user?</p>
  
  <pre><code>{% for approve in entry.docsApprovedBy.all() %}
     {% if approve.id == currentUser.id %}...{% endif %}
  {% endfor %}
  </code></pre>
  
Tags: <craft3><relations>
Title: Is there a way to check if entry is selected in relationship?
ThreadText: # Is there a way to check if entry is selected in relationship?
  
  (Asked by: username_0 on 2018-07-27)
  
  This project has a lot of user stuff. I need to display display different sections based on if the current user is in a field.
  
  Is there a better/faster way than looping through and checking if every user matched the current user?
  
  ```
  {% for approve in entry.docsApprovedBy.all() %}
     {% if approve.id == currentUser.id %}...{% endif %}
  {% endfor %}
  
  ```
  
  **Tags:** craft3, relations
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-07-27. Score: 2 | Accepted answer
  
  You should read the docs about [relations](https://docs.craftcms.com/v3/relations.html#the-relatedto-parameter)
  
  ```
  relatedEntries = craft.entries.relatedTo({targetElement: currentUser, field: 'docsApprovedBy'}).all()
  
  ```
  
  > **Comments:**
  > **username_0**: That's still doing an additional query which I was trying to avoid. I already have the entry. I was hoping for something like 'if user.id in entry.docsApprovedBy'. Thanks anyway.  
  > **username_1**: Then you can do `if currentUser.id in entry.field.ids()` but you can't do it without an additional query.  
  > **username_0**: Love it! Since I already have entry this is exactly what i wanted! Thanks  
  
  ---
  
  