Answers.Body: <p>If you're talking about a real parent-child relationship, so the child entry is a child of the parent entry in a structure, you don't need to go through the matrix field at all. You can simply use <a href="https://docs.craftcms.com/api/v3/craft-base-element.html#method-getparent" rel="nofollow noreferrer"><code>entry.getParent()</code></a> to get the parent. If this isn't the case – try to avoid using terminology that has a defined meaning within the system for something else, it only causes confusion.</p>
  <p>If the two entries are only related through the matrix field, the easiest way to get to the 'parent' is to find the matrix block first. You'll want to use a <a href="https://craftcms.com/docs/3.x/matrix-blocks.html#querying-matrix-blocks" rel="nofollow noreferrer">matrix block query</a> to find the matrix block that has the relationship you're looking for:</p>
  <pre class="lang-twig prettyprint-override"><code>{% set matrixBlock = craft.matrixBlocks()
      .relatedTo({ targetElement: entry })
      .one()
  %}
  </code></pre>
  <p>You can narrow this down further by specifying the field the relationship is on (see <a href="https://craftcms.com/docs/3.x/relations.html#simple-relationships" rel="nofollow noreferrer">Relations</a> for details), the block type, etc. Keep in mind that their may be more than one match, so make sure your conditions can only match one block, or use <code>.all()</code> instead of <code>.one()</code> and look for the block you want in the results.</p>
  <p>Once you have the matrix block with the relationship to your current entry, you can access the owner (the entry the block belongs to) using the <a href="https://docs.craftcms.com/api/v3/craft-records-matrixblock.html#method-getowner" rel="nofollow noreferrer"><code>MatrixBlock::getOwner</code> method</a>:</p>
  <pre class="lang-twig prettyprint-override"><code>{% set relatedEntry = matrixBlock.getOwner() %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-02T18:19:57.897Z
Answers.Text: Thank you. That worked perfectly - didn't know about matrix queries.
  
  so if it's not a parent entry cause it's not part of a structure, then what is it? I'm describing a relationship between one entry and another. one is the parent and the other is the child.
Answers.UserDisplayName: CreateSean
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-03T09:04:25.353Z
Answers.Text: @CreateSean Relationships between elements are many-to-many, so not hierarchical. I'd use source/target terminology, the element with the entries field being the source and the element being selected in that field the target. This is also the [terminology used for `relatedTo` queries](https://craftcms.com/docs/3.x/relations.html#advanced-relationships). The matrix block introduces a level of indirection, so technically, the matrix block is the source, the selected entry is the target, and the entry you're looking for is the owner of the matrix block, not directly related to the target.
Answers.UserDisplayName: MoritzLost
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-02T08:52:07.470Z
Answers.LastActivityDate: 2022-02-02T08:52:07.470Z
Answers.UserDisplayName: MoritzLost
Body: <p>I have a parent entry with a matrix field and one of the blocks has a relationship to a child entry.</p>
  <p>How do I access the parent entry from the child entry page?</p>
  <p>tried this, where eddChapter is the parent entry but it returns <code>null</code>.</p>
  <pre><code>  {% set chapter = craft.entries.section('eddChapter').relatedTo(entry).one() %}
    {{ dump(chapter) }}
  </code></pre>
  
Tags: <templating><relatedto>
Title: Get parent entry from child entry where relationship is in parent matrix field
ThreadText: # Get parent entry from child entry where relationship is in parent matrix field
  
  (Asked by: username_0 on 2022-02-01)
  
  I have a parent entry with a matrix field and one of the blocks has a relationship to a child entry.
  
  How do I access the parent entry from the child entry page?
  
  tried this, where eddChapter is the parent entry but it returns `null`.
  
  ```
    {% set chapter = craft.entries.section('eddChapter').relatedTo(entry).one() %}
    {{ dump(chapter) }}
  
  ```
  
  **Tags:** templating, relatedto
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-02-02. Score: 2 | Accepted answer
  
  If you're talking about a real parent-child relationship, so the child entry is a child of the parent entry in a structure, you don't need to go through the matrix field at all. You can simply use [`entry.getParent()`](https://docs.craftcms.com/api/v3/craft-base-element.html#method-getparent) to get the parent. If this isn't the case – try to avoid using terminology that has a defined meaning within the system for something else, it only causes confusion.
  
  If the two entries are only related through the matrix field, the easiest way to get to the 'parent' is to find the matrix block first. You'll want to use a [matrix block query](https://craftcms.com/docs/3.x/matrix-blocks.html#querying-matrix-blocks) to find the matrix block that has the relationship you're looking for:
  
  ```twig
  {% set matrixBlock = craft.matrixBlocks()
      .relatedTo({ targetElement: entry })
      .one()
  %}
  
  ```
  
  You can narrow this down further by specifying the field the relationship is on (see [Relations](https://craftcms.com/docs/3.x/relations.html#simple-relationships) for details), the block type, etc. Keep in mind that their may be more than one match, so make sure your conditions can only match one block, or use `.all()` instead of `.one()` and look for the block you want in the results.
  
  Once you have the matrix block with the relationship to your current entry, you can access the owner (the entry the block belongs to) using the [`MatrixBlock::getOwner` method](https://docs.craftcms.com/api/v3/craft-records-matrixblock.html#method-getowner):
  
  ```twig
  {% set relatedEntry = matrixBlock.getOwner() %}
  
  ```
  
  > **Comments:**
  > **username_0**: Thank you. That worked perfectly - didn't know about matrix queries.  so if it's not a parent entry cause it's not part of a structure, then what is it? I'm describing a relationship between one entry and another. one is the parent and the other is the child.  
  > **username_1**: @username_0 Relationships between elements are many-to-many, so not hierarchical. I'd use source/target terminology, the element with the entries field being the source and the element being selected in that field the target. This is also the [terminology used for `relatedTo` queries](https://craftcms.com/docs/3.x/relations.html#advanced-relationships). The matrix block introduces a level of indirection, so technically, the matrix block is the source, the selected entry is the target, and the entry you're looking for is the owner of the matrix block, not directly related to the target.  
  
  ---
  
  