Voting API doesn't show nodes with no votes in Views 2
| Project: | Voting API |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | task |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | closed |
So after looking a lot, I finally realized what the problem is. This issue made me realize the solution #284292: Where's Views Argument Handling Code
The votingapi_cache table is inner joined to the node table. This means that the intersection of the nodes in the node table and the nodes in the votingapi_cache table are shown. What I really wanted instead was all of the possible nodes + the fields from the nodes which had been voted on. This is a left join instead.
So I created a very, very small module to do this, and I need feedback to make sure this will work as I expect it to.
In a module, I called it site_tweaks.module I put the following:
<?php
// $Id$
/**
* @file
* Makes minor tweaks in a few modules
*/
/**
* Implementation of hook_views_query_alter().
*/
function site_tweaks_views_query_alter(&$view, &$query) {
// note here: if you want to affect your views, you need to put your view names in there.
if ($view->name === 'My_Resources' || $view->name === 'All_Resources') {
$query->table_queue['votingapi_cache_node_percent_vote_average']['join']->type = 'left';
}
}
?>(include the php tags).
In another file called site_tweaks.info, I put the following:
; $Id$
name = Site Tweaks
description = Modify other modules in here.
package = Pedagogle
core = 6.xI placed both of these inside a folder called site_tweaks in my modules folder. Enabled the module. Navigate to my view, and voila, all of my nodes of the appropriate type, including ones without any votes, are included.
If this is the right way to do this (and I tried every possible way I could think of using the Views UI), can we add this to the documentation for this module?

#1
Usually this table gets joined using a relationship. The INNER JOIN happens if you check the box 'require this relatonship'. At least thats my first thought upon reading this ...
#2
Hrmm, well let me test it and confirm you are right. I do see I have checked "require this relationship".
Dave
#3
subscribing. my problem seems similar but may be a separate issue. i've got require this relationship disabled but i need the sum of votes and for nodes without votes they aren't included.
#4
talked to merlin on irc and he suggested using COALESCE(field, 0) to force the NULL values to zero so the could be compared. i extended views_handler_filter_numeric to force the operators to coalesce. all-in-all a pretty simple fix that works like a charm.
#5
[12:36pm] merlinofchaos:drewish: Smaller patch: Override $query instead of the operators, and change $field directly
[12:36pm] drewish:
merlinofchaos: well the thing i like about this is that i still allows is null
[12:36pm] drewish:
if you want it
[12:36pm] drewish:
or is not null
[12:37pm] drewish:
merlinofchaos: would that work overriding query?
[12:37pm] merlinofchaos:
OH I see.
[12:37pm] merlinofchaos:
Hm.
[12:37pm] merlinofchaos:
You're right that would break those operators.
[12:37pm] merlinofchaos:
Carry on then!
#6
Hi every one,
I am using votint module and its working fine at my local pc but when i use this from my server its working but voting images not showing to vote some onee....please tell me how can i solve this issue .....
#7
Just committed this to the dev branch. Thanks, drewish!
#8
Automatically closed -- issue fixed for 2 weeks with no activity.
#9
"votingapi_views_handler_filter_value.inc" is missing on the Dev release.
#10
I'm also getting this error
#11
This has been fixed for a while in the official supported releases.
#12
Automatically closed -- issue fixed for 2 weeks with no activity.