cannot get vote values through nodereference relationship
gunzip - June 2, 2009 - 19:43
| Project: | Voting API |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
i have two content types. "application" and "reviews". reviews can be voted (with fivestar) and so do applications (multiple axis through fivestar). i want a block with the list of review and the overall rating of the __application__ aside. so i added a relationship for the node-referred content (call this: relative application) and another relationship "vote results" that uses the latter.
it seems that this doesn't work as the join of votingapi_cache results are made with the node table (read: review table) instead of the content_type_application. My view follows:
$view = new view;
$view->name = 'prova';
$view->description = 'prova';
$view->tag = 'block, home';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(
'field_application_ref_nid' => array(
'label' => 'Relative application',
'required' => 1,
'delta' => -1,
'id' => 'field_application_ref_nid',
'table' => 'node_data_field_application_ref',
'field' => 'field_application_ref_nid',
'relationship' => 'none',
),
'votingapi_cache' => array(
'label' => 'Voting results',
'required' => 0,
'votingapi' => array(
'value_type' => 'percent',
'tag' => 'overall',
'function' => 'average',
),
'id' => 'votingapi_cache',
'table' => 'node',
'field' => 'votingapi_cache',
'relationship' => 'field_application_ref_nid',
),
));
$handler->override_option('fields', array(
'title' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'link_to_node' => 1,
'exclude' => 0,
'id' => 'title',
'table' => 'node',
'field' => 'title',
'relationship' => 'none',
),
'value' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'set_precision' => FALSE,
'precision' => 0,
'decimal' => '.',
'separator' => ',',
'prefix' => '',
'suffix' => '',
'appearance' => '',
'exclude' => 0,
'id' => 'value',
'table' => 'votingapi_cache',
'field' => 'value',
'relationship' => 'votingapi_cache',
),
));
$handler->override_option('filters', array(
'type' => array(
'operator' => 'in',
'value' => array(
'review' => 'review',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
),
));
$handler->override_option('access', array(
'type' => 'none',
));
$handler->override_option('title', 'New reviews');
$handler->override_option('empty', 'No reviews yet.');
$handler->override_option('empty_format', '1');
$handler->override_option('items_per_page', 4);
$handler->override_option('use_pager', '0');
$handler->override_option('style_options', array(
'grouping' => '',
));
$handler = $view->new_display('block', 'Block', 'block_1');
$handler->override_option('block_description', '');
$handler->override_option('block_caching', -1);and this is the erroneous generated query:
SELECT node.nid AS nid,
node.title AS node_title,
votingapi_cache_node_percent_overall_average.value AS votingapi_cache_node_percent_overall_average_value
FROM node node
LEFT JOIN content_type_review node_data_field_application_ref ON node.vid = node_data_field_application_ref.vid
INNER JOIN node node_node_data_field_application_ref ON node_data_field_application_ref.field_application_ref_nid = node_node_data_field_application_ref.nid
LEFT JOIN votingapi_cache votingapi_cache_node_percent_overall_average ON node.nid = votingapi_cache_node_percent_overall_average.content_id AND (votingapi_cache_node_percent_overall_average.content_type = 'node' AND votingapi_cache_node_percent_overall_average.value_type = 'percent' AND votingapi_cache_node_percent_overall_average.tag = 'overall' AND votingapi_cache_node_percent_overall_average.function = 'average')
WHERE node.type in ('review')afaik it should be (note that the aliased table differs)
LEFT JOIN votingapi_cache votingapi_cache_node_percent_overall_average ON node_node_data_field_application_ref.nid = ...to get the application votes.

#1
Here is a quick patch I put together. This is very lightly tested to see if it affects any other functionality but it is a pretty straight forward change.
#2
Committed to the dev branch, will be rolled into the next release. Thanks!
#3
Automatically closed -- issue fixed for 2 weeks with no activity.
#4
This patch worked for me, thanks
However, it does not allow me to vote correctly while in views via the fivestar widget. And it pulls the wrong display settings. See this issue I opened #562614: Fivestar voting in views with node relationships Thanks