3

I have a view of Planet content types. These Planets have a node reference field for Trade Routes to reference other Planets. I'm attempting to output both the current Planet's x/y coordinates, as well as the x/y coordinates of the Planets it references in it's Trade Routes field.

Setting up the fields with each Planet outputting its own x/y and the x/y fields again but using the Trade Route relationship this time results in each Planet being returned as a row once per Trade Route it is storing, instead of returning an array of x/y like I would expect.

What am I doing wrong here?

  • I had something similar, try changing your relationships to "required". it fixed my problem. give it a shot – saadlulu Sep 22 '12 at 10:04
3

Maybe You can try to use the Query Parameter and check the "Distinct" option to have distinct result :

enter image description here

enter image description here

3

I've tried every recomendation I've found and nothing seems to do the trick perfecly. The most precise result I can get is filtering the views results before rendering the view, like this:

function YOURTHEMENAME_views_pre_render(&$view) {
  $used_nids = array();
  $new_view_result = array();

  if ($view->name == 'YOURVIEWNAME') {
    foreach ($view->result as $row) {
        if (!in_array($row->nid, $used_nids)) {
          $new_view_result[] = $row;
          $used_nids[] = $row->nid;
        }
    }

    $view->result = $new_view_result;
  }
}

Put that snippet in your template.php and replace YOURTHEMENAME and YOURVIEWNAME with your values, you should have no duplicates. HOWEVER, I'm finding that this creates pages with less rows than expected, for example, if you want 10 results per page and your view has 8 duplicates in the first page, the first page would have just 2 rows. So, take my code as a partial result and only if you don't care having less results per page or if you are displaying all results at once.

2

you can use an "attachment" to show the related content. This article describes it well.

Or you could use the table format and group by the first field. That will put the first field above the table and just show the values of the 2nd field in the table.

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.