<p>I have a front-end form that allows registered users to edit content. In this case, it is a podcast. I have multiple podcasts that blog to different providers.</p>

<p>Here is how I am selecting the provider that belongs to the <code>currentUser</code>:</p>

<pre><code>{% set provider = craft.entries()
    .section('provider').relatedTo({
        element: currentUser,
        field: 'contributors'
    }).one() %}
</code></pre>

<p>Works great. From there, here is how I am selecting the podcast that belongs to the current provider (selected above).</p>

<pre><code>{% set podcast = craft.entries()
    .section('podcast').relatedTo({
        targetElement: provider,
        field: 'podcastProvider'
    }).one() %}
</code></pre>

<p>This works well, I am able to get the podcast and do whatever with it.</p>

<p>However, I'd also like to make a double check that this podcast belongs to the current provider - which belongs to the <code>currentUser</code>. Maybe that's overkill, I'd like to hear thoughts about that...</p>

<p>Here is what I am trying, but not having much luck.</p>

<pre><code>{% set podcast = craft.entries()
    .section('podcast')
    .relatedTo(['and',
        {targetElement: provider, field: 'podcastProvider'},
        {targetElement: currentUser, field: 'provider.contributors'}
    ]).one() %}
</code></pre>

<p><code>currentUser</code> is of course the user that is currently logged in. <code>contributors</code> is a <code>users</code> field that exists on the provider entry.</p>

<p>So, I was trying to make double-sure that the person who was logged in, not only belong to the provider, but the podcast they are editing belongs to the provider - that they (the currentUser) belongs to.</p>

<p>Or, is this completely overkill? Thank you for your suggestions!</p>

CC BY-SA 4.0
2018-10-30T16:00:38.953Z
If `contributors` is a users field for the provider how is that field supposed to be related to a podcast? I don't really see any relation or ways how Craft should know what elements to fetch with your current setup
Robin Schambach
CC BY-SA 4.0
2018-10-30T16:07:13.073Z
The podcast is related to the provider, which is related to the `currentUser`. Does that help? I've updated my question, I did not have my final query entered correctly.
Damon
CC BY-SA 4.0
2018-10-30T16:08:49.500Z
I thought so but Craft can't search for entries that are related to a certain other related element. You can't skip relation levels via related to param without creating custom joins and rules via sql
Robin Schambach
CC BY-SA 4.0
2018-10-30T16:10:55.817Z
Fair enough - thank you very much for your feedback! What I have works well, so perhaps it's overkill anyway.
Damon
<craft3><relations>
How can I use a double relation to include the currentUser as criteria?
# How can I use a double relation to include the currentUser as criteria?

(Asked by: username_0 on 2018-10-30)

I have a front-end form that allows registered users to edit content. In this case, it is a podcast. I have multiple podcasts that blog to different providers.
Here is how I am selecting the provider that belongs to the currentUser:
{% set provider = craft.entries()
    .section('provider').relatedTo({
        element: currentUser,
        field: 'contributors'
    }).one() %}

Works great. From there, here is how I am selecting the podcast that belongs to the current provider (selected above).
{% set podcast = craft.entries()
    .section('podcast').relatedTo({
        targetElement: provider,
        field: 'podcastProvider'
    }).one() %}

This works well, I am able to get the podcast and do whatever with it.
However, I'd also like to make a double check that this podcast belongs to the current provider - which belongs to the currentUser. Maybe that's overkill, I'd like to hear thoughts about that...
Here is what I am trying, but not having much luck.
{% set podcast = craft.entries()
    .section('podcast')
    .relatedTo(['and',
        {targetElement: provider, field: 'podcastProvider'},
        {targetElement: currentUser, field: 'provider.contributors'}
    ]).one() %}

currentUser is of course the user that is currently logged in. contributors is a users field that exists on the provider entry.
So, I was trying to make double-sure that the person who was logged in, not only belong to the provider, but the podcast they are editing belongs to the provider - that they (the currentUser) belongs to.
Or, is this completely overkill? Thank you for your suggestions!

**Tags:** craft3, relations

> **Comments:**
> **username_1**: If `contributors` is a users field for the provider how is that field supposed to be related to a podcast? I don't really see any relation or ways how Craft should know what elements to fetch with your current setup  
> **username_0**: The podcast is related to the provider, which is related to the `currentUser`. Does that help? I've updated my question, I did not have my final query entered correctly.  
> **username_1**: I thought so but Craft can't search for entries that are related to a certain other related element. You can't skip relation levels via related to param without creating custom joins and rules via sql  
> **username_0**: Fair enough - thank you very much for your feedback! What I have works well, so perhaps it's overkill anyway.  

---

## 0 answers

