Drupal Views: Render Null Result for Relationship as 0
Posted
by
Kyle S
on Stack Overflow
See other posts from Stack Overflow
or by Kyle S
Published on 2011-01-06T23:48:23Z
Indexed on
2011/01/06
23:54 UTC
Read the original article
Hit count: 156
drupal
|drupal-views
I have a View configured in Drupal to return nodes, sorting them by their average vote in descending order. For the purpose of the View, the value of the average votes is a Relationship. I noticed that nodes with no votes are displayed after nodes with a negative average. Nodes with no votes should have an average of 0, but I believe the MySQL JOIN
is causing NULL
values to be returned (as there are no matching rows in the joined table, since a row is created after the first vote is cast for that item).
I discovered that with MySQL it is possible to output all values that are NULL
in a column as another value with IFNULL(column_name,'other value')
.
I feel like I would need to modify the Views module in order to obtain this functionality, but I'm hoping that there is some sort of option that returns NULL
values in a relation (a relation doesn't exist for the item) as 0 instead of NULL
, so that I can properly sort the nodes.
The modules I am using include Views, Voting API, Vote Up/Down, and CTools.
Thanks.
© Stack Overflow or respective owner