Answers.Body: <p>If <code>currentUser</code> isn't defined, it returns <code>null</code>. So what's probably happening is you have people visiting the site who don't have user accounts or aren't signed in, which means the <code>currentUser</code> variable is set to <code>null</code> for them. So in your query you end up passing <code>null</code> to the <code>authorId</code> param, which means it will get everything (<code>null</code> being the default if I'm not mistaken). Most likely in your local environment you did all your testing while being signed in.</p>
  
  <p>To solve, you'll want to surround your code in a conditional:</p>
  
  <pre><code>{% if currentUser %}
      {% set campaigns = craft.entries.section('campaigns').authorId(currentUser.id).all() %}
      {% set proposals = craft.entries.section('proposals').relatedTo(campaigns).all() %}
      {% set proposalsByGroup = proposals|group('proposalStatus') %}
  {% else %}
      Please sign in to view your proposals...
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-20T14:22:20.500Z
Answers.LastActivityDate: 2019-05-20T14:22:20.500Z
Answers.UserDisplayName: Jalen Davenport
Body: <p>I'm currently doing the following query, it's working nicely on my local environment but on Production it's allowing all users to see all entries which is really strange? I can't see anything wrong with my code that would be causing this to break?</p>
  
  <pre><code>{% set campaigns = craft.entries.section('campaigns').authorId(currentUser.id).all() %}
  {% set proposals = craft.entries.section('proposals').relatedTo(campaigns).all() %}
  {% set proposalsByGroup = proposals|group('proposalStatus') %}
  </code></pre>
  
Tags: <templating>
Title: Related Entries to Users
ThreadText: # Related Entries to Users
  
  (Asked by: username_0 on 2019-05-20)
  
  I'm currently doing the following query, it's working nicely on my local environment but on Production it's allowing all users to see all entries which is really strange? I can't see anything wrong with my code that would be causing this to break?
  
  ```
  {% set campaigns = craft.entries.section('campaigns').authorId(currentUser.id).all() %}
  {% set proposals = craft.entries.section('proposals').relatedTo(campaigns).all() %}
  {% set proposalsByGroup = proposals|group('proposalStatus') %}
  
  ```
  
  **Tags:** templating
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-05-20. Score: 1
  
  If `currentUser` isn't defined, it returns `null`. So what's probably happening is you have people visiting the site who don't have user accounts or aren't signed in, which means the `currentUser` variable is set to `null` for them. So in your query you end up passing `null` to the `authorId` param, which means it will get everything (`null` being the default if I'm not mistaken). Most likely in your local environment you did all your testing while being signed in.
  
  To solve, you'll want to surround your code in a conditional:
  
  ```
  {% if currentUser %}
      {% set campaigns = craft.entries.section('campaigns').authorId(currentUser.id).all() %}
      {% set proposals = craft.entries.section('proposals').relatedTo(campaigns).all() %}
      {% set proposalsByGroup = proposals|group('proposalStatus') %}
  {% else %}
      Please sign in to view your proposals...
  {% endif %}
  
  ```
  
  
  ---
  
  