3

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;
        }

    }
2
  • 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(); May 29 '18 at 20:11
  • Would you mind adding that solution as an official answer, Brett? Might end up helping someone in the future. :)
    – Brad Bell
    May 30 '18 at 0:44
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();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.