Answers.Body: <p>figured this one out on my own, so to get all of the related objects, I just needed to change the above query to <code>$buildings = $location-&gt;buildings-&gt;all();</code></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-30T04:00:17.757Z
Answers.LastActivityDate: 2018-05-30T04:00:17.757Z
Answers.UserDisplayName: Brett Moore
Body: <p>So I've got this which accurately gives me the desired relation block within my matrix, but how do I actually get the Entry object from a relation field?</p>
  
  <pre><code>$project = Entry::find()-&gt;id($projectId)-&gt;one();
  
  foreach ($project-&gt;location as $locations) {
          if ($locations-&gt;getType()-&gt;name === 'Locations') {
              // Grab a building from the block. 
              // Right now this just returns the relation table ID, I'd like the actual Entry object with it's attributes.
              $buildings = $locations-&gt;buildings;
          }
  
      }
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-29T20:11:50.187Z
Comments.Text: Hey there - figured this one out on my own, so to get all of the related objects, I just needed to change the above query to `$buildings = $location->buildings->all();`
Comments.UserDisplayName: Brett Moore
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-30T00:44:40.793Z
Comments.Text: Would you mind adding that solution as an official answer, Brett?  Might end up helping someone in the future. :)
Comments.UserDisplayName: Brad Bell
Tags: <plugin-development><plugins>
Title: Get the related entry from an Entries field in a Matrix block within a plugin craft 3
ThreadText: # Get the related entry from an Entries field in a Matrix block within a plugin craft 3
  
  (Asked by: username_0 on 2018-05-29)
  
  So I've got this which accurately gives me the desired relation block within my matrix, but how do I actually get the Entry object from a relation field?
  
  ```
  $project = Entry::find()->id($projectId)->one();
  
  foreach ($project->location as $locations) {
          if ($locations->getType()->name === 'Locations') {
              // Grab a building from the block. 
              // Right now this just returns the relation table ID, I'd like the actual Entry object with it's attributes.
              $buildings = $locations->buildings;
          }
  
      }
  
  ```
  
  **Tags:** plugin-development, plugins
  
  > **Comments:**
  > **username_0**: Hey there - figured this one out on my own, so to get all of the related objects, I just needed to change the above query to `$buildings = $location->buildings->all();`  
  > **username_1**: Would you mind adding that solution as an official answer, username_0?  Might end up helping someone in the future. :)  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2018-05-30. Score: 2
  
  figured this one out on my own, so to get all of the related objects, I just needed to change the above query to `$buildings = $location->buildings->all();`
  
  
  ---
  
  