How do I avoid duplicates when using a reference field?
I removed the duplicates using hook_views_pre_render().

function hook_views_pre_render(\Drupal\views\ViewExecutable $view) { 
  if ($view-&gt;id() == 'my_view_id') {
    $filtered_nids = array();

    foreach ($view-&gt;result as $key =&gt; $row) {
      if (in_array($row-&gt;nid, $filtered_nids)) {
        unset($view-&gt;result[$key]); // remove the duplicate
      } else {
        $filtered_nids[] = $row-&gt;nid;
      }
    }
  } 
}


Probably not the best solution, but it works for my case.