Answers.Body: <p>The error you’re getting is a bug in Craft. (Just fixed that for the next release.)</p>
  
  <p>To work around it, replace the <code>{% set authors ... %}</code> tag with:</p>
  
  
  
  <pre><code>{% if bookIds|length %}
      {% set authors = craft.entries()
          .section('authors')
          .relatedTo({ sourceElement: bookIds, field: 'books' })
          .all() %}
  {% else %}
      {% set authors = [] %}
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-17T15:36:52.437Z
Answers.Text: Thanks very much Brandon, but it appears to be giving the same error: http://textuploader.com/d4uwl
Answers.UserDisplayName: Rivu Meyano
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-17T15:38:27.857Z
Answers.Text: @RivuMeyano What does `{{ dump(bookIds) }}` output for you?
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-17T16:01:24.247Z
Answers.Text: If I only include that in my template, then I get and "Unknown "dump" function" error, but I guess that's because bookIds hasn't been defined.
  
  It appears to be the first block of code that gives the  "Undefined offset: 0" error, but if I include that in order to have the Dump function do something, I will of course still get the  "Undefined offset: 0" error.
Answers.UserDisplayName: Rivu Meyano
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-17T16:02:58.747Z
Answers.Text: Sorry, you should enable Dev Mode first. (Set `'devMode' => true` in craft/config/general.php.) And you should put that tag after the `{% set bookIds = ...  %}` tag, but remove the author code after it.
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-17T16:06:42.173Z
Answers.Text: Ah - here's what Dump gives me: https://pictr.com/image/UwhxP
Answers.UserDisplayName: Rivu Meyano
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-17T16:08:19.333Z
Answers.Text: Looks like it hasn’t even made it to the `dump()` function. It’s saying your `publisher` variable doesn’t exist. That was just a placeholder in the example for whatever your publisher entry variable is called. If you’re on the publisher’s entry template, maybe it’s actually `entry`?
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-17T16:15:26.170Z
Answers.Text: Yes I'm on the publisher's entry template. The channel is Publisher, and the relationship field from Books to Publisher is also called Publisher.
  
  If change the targetElement to 'entry' as in the link below, the dump function gives:  array(1) { [0]=> string(2) "33" }
  
  http://textuploader.com/d4ubu
Answers.UserDisplayName: Rivu Meyano
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-17T16:28:18.613Z
Answers.Text: OK, and now if you remove the `dump()` function and bring back the author code, does it work as expected?
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-17T16:43:12.587Z
Answers.Text: Yes the error's now gone, so that must be working (just have to figure out how to put the results on the page..). Thank you!
Answers.UserDisplayName: Rivu Meyano
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-17T14:58:20.327Z
Answers.LastActivityDate: 2017-10-17T14:58:20.327Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>I want to do exactly this: <strong><a href="https://github.com/craftcms/cms/issues/1640" rel="nofollow noreferrer">Multi-step &amp; bi-directional relations with relatedTo (#1640)</a></strong></p>
  
  <blockquote>
    <p>Common example: Let’s say you have Books, Authors, and Publishers, and two relationship fields on the Books channel: <code>author</code> and <code>publisher</code>. On a Publisher’s page, you want to list all of the Authors that have published books with them.</p>
  </blockquote>
  
  <p>Here’s what I’ve tried:</p>
  
  <pre><code>{% set bookIds = craft.entries()
  .section('books')
  .relatedTo({ targetElement: publisher, field: 'publisher' })
  .ids() %}
  
  {% set authors = craft.entries()
  .section('authors')
  .relatedTo({ sourceElement: bookIds, field: 'books' })
  .all() %}
  </code></pre>
  
  <p>However the code results in an "Undefined offset: 0" error. The error seems to occur in the first block of code.</p>
  
  <p>Additionally, I'm not sure about the field in the penultimate line, shouldn't it be 'authors' rather than 'books'?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-17T10:42:53.337Z
Comments.Text: Search your logs (`craft/storage/runtime/logs/craft.log`, etc.) for the error message you’re getting. Can you post the stack trace that gets logged with it?
Comments.UserDisplayName: Brandon Kelly
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-17T10:46:51.243Z
Comments.Text: Yes you’re right, `field: 'books'` should have been `field: 'author'`. Just updated the GH issue.
Comments.UserDisplayName: Brandon Kelly
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-17T12:30:33.830Z
Comments.Text: Thank you Brandon, here's the log:
  
  http://textuploader.com/d4uuk
Comments.UserDisplayName: Rivu Meyano
Tags: <relations>
Title: Filtering by cousins
ThreadText: # Filtering by cousins
  
  (Asked by: username_0 on 2017-10-17)
  
  I want to do exactly this: **[Multi-step & bi-directional relations with relatedTo (#1640)](https://github.com/craftcms/cms/issues/1640)**
  
  > Common example: Let’s say you have Books, Authors, and Publishers, and two relationship fields on the Books channel: `author` and `publisher`. On a Publisher’s page, you want to list all of the Authors that have published books with them.
  
  Here’s what I’ve tried:
  
  ```
  {% set bookIds = craft.entries()
  .section('books')
  .relatedTo({ targetElement: publisher, field: 'publisher' })
  .ids() %}
  
  {% set authors = craft.entries()
  .section('authors')
  .relatedTo({ sourceElement: bookIds, field: 'books' })
  .all() %}
  
  ```
  
  However the code results in an "Undefined offset: 0" error. The error seems to occur in the first block of code.
  
  Additionally, I'm not sure about the field in the penultimate line, shouldn't it be 'authors' rather than 'books'?
  
  **Tags:** relations
  
  > **Comments:**
  > **username_1**: Search your logs (`craft/storage/runtime/logs/craft.log`, etc.) for the error message you’re getting. Can you post the stack trace that gets logged with it?  
  > **username_1**: Yes you’re right, `field: 'books'` should have been `field: 'author'`. Just updated the GH issue.  
  > **username_0**: Thank you username_1, here's the log:  http://textuploader.com/d4uuk  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-10-17. Score: 1 | Accepted answer
  
  The error you’re getting is a bug in Craft. (Just fixed that for the next release.)
  
  To work around it, replace the `{% set authors ... %}` tag with:
  
  ```
  {% if bookIds|length %}
      {% set authors = craft.entries()
          .section('authors')
          .relatedTo({ sourceElement: bookIds, field: 'books' })
          .all() %}
  {% else %}
      {% set authors = [] %}
  {% endif %}
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks very much username_1, but it appears to be giving the same error: http://textuploader.com/d4uwl  
  > **username_1**: @username_0 What does `{{ dump(bookIds) }}` output for you?  
  > **username_0**: If I only include that in my template, then I get and "Unknown "dump" function" error, but I guess that's because bookIds hasn't been defined.  It appears to be the first block of code that gives the  "Undefined offset: 0" error, but if I include that in order to have the Dump function do something, I will of course still get the  "Undefined offset: 0" error.  
  > **username_1**: Sorry, you should enable Dev Mode first. (Set `'devMode' => true` in craft/config/general.php.) And you should put that tag after the `{% set bookIds = ...  %}` tag, but remove the author code after it.  
  > **username_0**: Ah - here's what Dump gives me: https://pictr.com/image/UwhxP  
  > **username_1**: Looks like it hasn’t even made it to the `dump()` function. It’s saying your `publisher` variable doesn’t exist. That was just a placeholder in the example for whatever your publisher entry variable is called. If you’re on the publisher’s entry template, maybe it’s actually `entry`?  
  > **username_0**: Yes I'm on the publisher's entry template. The channel is Publisher, and the relationship field from Books to Publisher is also called Publisher.  If change the targetElement to 'entry' as in the link below, the dump function gives:  array(1) { [0]=> string(2) "33" }  http://textuploader.com/d4ubu  
  > **username_1**: OK, and now if you remove the `dump()` function and bring back the author code, does it work as expected?  
  > **username_0**: Yes the error's now gone, so that must be working (just have to figure out how to put the results on the page..). Thank you!  
  
  ---
  
  