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

CC BY-SA 4.0
2018-07-27T18:14:28.113Z
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.
Amanda Lutz
CC BY-SA 4.0
2018-07-27T18:16:20.547Z
Then you can do `if currentUser.id in entry.field.ids()` but you can't do it without an additional query.
Robin Schambach
CC BY-SA 4.0
2018-07-28T14:52:24.833Z
Love it! Since I already have entry this is exactly what i wanted! Thanks
Amanda Lutz
CC BY-SA 4.0
2018-07-27T14:58:48.097Z
2018-07-27T14:58:48.097Z
Robin Schambach
<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>

<craft3><relations>
Is there a way to check if entry is selected in relationship?
# 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 
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  

---

