Answers.Body: <p>There could be corrupt data in your remote database. I tried to answer a similar case some weeks ago: <a href="https://craftcms.stackexchange.com/q/5164/125">"Entries related to Users"</a>, where the code was right, but Craft returned the wrong entries.</p>
  
  <p>I'd check if it helps to clear the database and do a fresh import from you local environment.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-04T11:55:45.857Z
Answers.Text: Yep. You're right. That was it. Going to be a pain updating these entries again but at least I caught it early.
Answers.UserDisplayName: Dennis Eusebio
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-04T14:02:19.573Z
Answers.Text: Although, I did this and started to re-enter in the relations and it happened again :(
Answers.UserDisplayName: Dennis Eusebio
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-04T14:06:00.937Z
Answers.Text: Ohh no, @Dennis. I'm really sorry for you! :( ...best thing you can probably do now is to contact P&T support.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-04T08:25:11.367Z
Answers.LastActivityDate: 2015-03-04T08:25:11.367Z
Answers.LastEditDate: 2017-04-13T12:51:00.200Z
Answers.UserDisplayName: carlcs
Body: <p><strong>So I have these sections and fields that I'm dealing with:</strong></p>
  
  <p>candidates</p>
  
  <ul>
  <li>Name</li>
  <li>Pic</li>
  <li>Bio</li>
  </ul>
  
  <p>answers</p>
  
  <ul>
  <li>relatedQuestion</li>
  <li>Body</li>
  <li>relatedCandidate</li>
  </ul>
  
  <p>questions</p>
  
  <ul>
  <li>title</li>
  <li>body</li>
  </ul>
  
  <p>candidateGroup</p>
  
  <ul>
  <li>title</li>
  </ul>
  
  <p><strong>I'm outputting a single page using the question:</strong></p>
  
  <p>Question and Info</p>
  
  <p>Candidate Group Name</p>
  
  <ul>
  <li><p>Candidate</p>
  
  <ul>
  <li>Answer</li>
  </ul></li>
  <li><p>Candidate</p>
  
  <ul>
  <li>Answer</li>
  </ul></li>
  </ul>
  
  <p>... Repeats ...</p>
  
  <p><strong>So my current setup looks like this:</strong></p>
  
  <pre><code>{# Get the answers that are related to the question entry #}
  {% set relatedAnswers = craft.entries.section('answers').relatedTo(entry) %}
  
  {# Loop through categories #}
  {% for category in craft.categories.group('candidateGroup') %}
  
    {{ category.title }}
  
    {# Get me the candidates that belong to this category and have an answer related to this question entry #}
    {% set candidateAnswers = craft.entries.section('candidates').relatedTo('and',
      category,
      relatedAnswers
    ) %}
    {% for candidateAnswer in candidateAnswers %}
  
      {# Output the candidate's info and their answer #}
  
    {% endfor %}
  {% endfor %}
  </code></pre>
  
  <p>I feel like this is right and it seems to be working locally but when I get it live on the site it's having issues recognizing what "entry" it's a part of. No matter what entry I go to via url, it outputs the same answers.</p>
  
  <p>I tried to do a simple loop to see what relatedAnswers outputs, and it's the right information. It's just getting lost in that inner loop somehow.</p>
  
  <p><strong>Update:</strong>
  I believe it is working locally just fine. But for some reason, on my Media Temple hosted site, it's not outputting in the same manner. I double and triple checked all the fields and couldn't find any differences?</p>
  
  <p><strong>Update 2:</strong>
  I can't figure this out for the life of me. It works fine on local, just not on production. I checked the database to see if there anything out of the ordinary and it looked fine to me. I installed the introvert plugin to see if the relations were working properly and they seem to be just fine. Kind of lost at this point.</p>
  
  <p><strong>Updated 3</strong>
  I tried it another way:</p>
  
  <pre><code>&lt;div class="question__candidates"&gt;
    {% for category in craft.categories.group('candidateGroup') %}
      &lt;div class="question__row"&gt;
        &lt;h3&gt;{{ category.title }}&lt;/h3&gt;
        {% for answerEntry in craft.entries.section('answers').relatedTo('and',category,entry) %}
          &lt;div class="question__candidates__card"&gt;
            &lt;div class="question__candidates__card__header"&gt;
              &lt;div class="question__candidates__card__header__avatar"&gt;
                {% set relatedCandidate = craft.entries.section('candidates').relatedTo(answerEntry).first() %}
                {% set asset = relatedCandidate.avatar.first() %}
                &lt;a href="{{ relatedCandidate.url }}"&gt;&lt;img src="{{ asset.url }}" /&gt;&lt;/a&gt;
              &lt;/div&gt;
              &lt;div class="question__candidates__card__header__title"&gt;
                &lt;h4&gt;&lt;a href="{{ relatedCandidate.url }}"&gt;{{ relatedCandidate.title }}&lt;/a&gt;&lt;/h4&gt;
                &lt;p&gt;
                  {% set categoryCandidate = relatedCandidate.group.group('candidateGroup').first() %}
                  {{ categoryCandidate.title }}
                &lt;/p&gt;
              &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="question__candidates__card__content"&gt;
              {{ answerEntry.body }}
            &lt;/div&gt;
          &lt;/div&gt;
        {% else %}
          &lt;div class="slate blank"&gt;
            There are no answers from candidates in this group yet.
          &lt;/div&gt;
        {% endfor %}
      &lt;/div&gt;
    {% endfor %}
  &lt;/div&gt;
  </code></pre>
  
  <p>Unlike the other solution, my problem on the server is that it doesn't return any entries at all. I'm assuming it has something to do with that 'relatedTo(entry)'. It's like it doesn't recognize that at all. In the first case it just ignores it and  in this case it's like it can't read it.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-03-05T20:03:35.213Z
Comments.Text: I've responded to both of your support tickets... are you not getting them?
Comments.UserDisplayName: Brad Bell
Tags: <relations>
Title: How to structure this multiple relation?
ThreadText: # How to structure this multiple relation?
  
  (Asked by: username_0 on 2015-03-04)
  
  **So I have these sections and fields that I'm dealing with:**
  
  candidates
  
  * Name
  * Pic
  * Bio
  
  answers
  
  * relatedQuestion
  * Body
  * relatedCandidate
  
  questions
  
  * title
  * body
  
  candidateGroup
  
  * title
  
  **I'm outputting a single page using the question:**
  
  Question and Info
  
  Candidate Group Name
  
  * Candidate
  
    + Answer
  * Candidate
  
    + Answer
  
  ... Repeats ...
  
  **So my current setup looks like this:**
  
  ```
  {# Get the answers that are related to the question entry #}
  {% set relatedAnswers = craft.entries.section('answers').relatedTo(entry) %}
  
  {# Loop through categories #}
  {% for category in craft.categories.group('candidateGroup') %}
  
    {{ category.title }}
  
    {# Get me the candidates that belong to this category and have an answer related to this question entry #}
    {% set candidateAnswers = craft.entries.section('candidates').relatedTo('and',
      category,
      relatedAnswers
    ) %}
    {% for candidateAnswer in candidateAnswers %}
  
      {# Output the candidate's info and their answer #}
  
    {% endfor %}
  {% endfor %}
  
  ```
  
  I feel like this is right and it seems to be working locally but when I get it live on the site it's having issues recognizing what "entry" it's a part of. No matter what entry I go to via url, it outputs the same answers.
  
  I tried to do a simple loop to see what relatedAnswers outputs, and it's the right information. It's just getting lost in that inner loop somehow.
  
  **Update:**
  I believe it is working locally just fine. But for some reason, on my Media Temple hosted site, it's not outputting in the same manner. I double and triple checked all the fields and couldn't find any differences?
  
  **Update 2:**
  I can't figure this out for the life of me. It works fine on local, just not on production. I checked the database to see if there anything out of the ordinary and it looked fine to me. I installed the introvert plugin to see if the relations were working properly and they seem to be just fine. Kind of lost at this point.
  
  **Updated 3**
  I tried it another way:
  
  ```
  <div class="question__candidates">
    {% for category in craft.categories.group('candidateGroup') %}
      <div class="question__row">
        <h3>{{ category.title }}</h3>
        {% for answerEntry in craft.entries.section('answers').relatedTo('and',category,entry) %}
          <div class="question__candidates__card">
            <div class="question__candidates__card__header">
              <div class="question__candidates__card__header__avatar">
                {% set relatedCandidate = craft.entries.section('candidates').relatedTo(answerEntry).first() %}
                {% set asset = relatedCandidate.avatar.first() %}
                <a href="{{ relatedCandidate.url }}"><img src="{{ asset.url }}" /></a>
              </div>
              <div class="question__candidates__card__header__title">
                <h4><a href="{{ relatedCandidate.url }}">{{ relatedCandidate.title }}</a></h4>
                <p>
                  {% set categoryCandidate = relatedCandidate.group.group('candidateGroup').first() %}
                  {{ categoryCandidate.title }}
                </p>
              </div>
            </div>
            <div class="question__candidates__card__content">
              {{ answerEntry.body }}
            </div>
          </div>
        {% else %}
          <div class="slate blank">
            There are no answers from candidates in this group yet.
          </div>
        {% endfor %}
      </div>
    {% endfor %}
  </div>
  
  ```
  
  Unlike the other solution, my problem on the server is that it doesn't return any entries at all. I'm assuming it has something to do with that 'relatedTo(entry)'. It's like it doesn't recognize that at all. In the first case it just ignores it and in this case it's like it can't read it.
  
  **Tags:** relations
  
  > **Comments:**
  > **username_1**: I've responded to both of your support tickets... are you not getting them?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2015-03-04. Score: 1
  
  There could be corrupt data in your remote database. I tried to answer a similar case some weeks ago: ["Entries related to Users"](https://craftcms.stackexchange.com/q/5164/125), where the code was right, but Craft returned the wrong entries.
  
  I'd check if it helps to clear the database and do a fresh import from you local environment.
  
  > **Comments:**
  > **username_0**: Yep. You're right. That was it. Going to be a pain updating these entries again but at least I caught it early.  
  > **username_0**: Although, I did this and started to re-enter in the relations and it happened again :(  
  > **username_2**: Ohh no, @username_0. I'm really sorry for you! :( ...best thing you can probably do now is to contact P&T support.  
  
  ---
  
  