I am struggling since a couple of days with my problem now and I have no idea what else I can do to come to a stage of enlightenment.
In Drupal 8 I have a content type called "Release" and a content type "Article" which, among others, contains Reviews of Releases. So in Releases I created an entity reference field called "Review" which references Article content type.
For index pages I could create views of Articles and there I pretty easy could integrate the fields of the referencing release entity via the Relations section in views administration. There the reverse direction of a relationship is not a problem.
How do I access the fields of the release in a node--article.html.twig template?
Edited due to character limitation in the comments section (I hope this is allowed): Thank you so much, @JeremyM4an, but there was a little misunderstanding due to my bad explanation of the problem. I should have mentioned that article has a reference to a taxonomy term, called field_post_category.
So a review is an article with field_post_category == 'Review' and finally a release has an entity reference field, called field_review, referring to article. After reading your answer I tried this:
$category_field = $node->get('field_post_category');
$category_field = $category_field->getValue();
if( isset($category_field[0]['target_id']) && $category_field[0]['target_id'] ){
$term = taxonomy_term_load($category_field[0]['target_id']);
if($term && $term->get('name')->value == 'Reviews'){
$release = \Drupal::entityQuery('node')
->condition('type', 'release')
->condition('field_review.entity:node.nid', $node->id())
->execute();
// Load release node and store in variables.
$variables['release'] = Node::load(array_values($release)[0]);
}
}
But this does not work.