Sorting on a fields from a referenced content type - NULL values

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
ppc.coder's picture

Hi again,

I tried searching for this but couldn't find the right keywords :P I'm sure this is a common requirement.

What I want to do is sort my view on a field from a referenced content type. But the problem is that the sort column is coming back with all NULLs.

For example, say I have 2 content types: Sales and Province, where the Sales table has a node reference to Province. The Province type has a Display Order field that I want the view to be sorted on.

I defined a view with fields from Sales and the Display Order field from Province. I also defined a filter to only display nodes of Type: Sales.
The problem is that the Display Order field is showing NULLs. The odd thing is that the Province node's title is being picked up correctly.

| province | display_order | sale_date   |    sale_amount |
| ON       |               | feb 14 2010 |   8            |
| ON       |               | feb 14 2010 |   7            |

Has anyone had to do this and got it working?

Comments

It looks like this is a join

ppc.coder's picture

It looks like this is a join and filter issue.

The left most table is node which joins to the province content type table. However, in the where clause we only keep node.type = 'sales' so that would filter out all the provinces? Is views not able to support selecting fields from content types used lookup tables?

Finally figured this one out.

ppc.coder's picture

Finally figured this one out. I was right about it having to do with the Join.

  1. Add the relationship to the Province content type.
  2. Now, in your fields list, when you click on the Display Order field it should give you a dropdown to select the "Relationship" to use. Select Province.