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.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | shop_products_view.txt | 9 KB | akalyptos |
| #7 | views.png | 71.89 KB | akalyptos |
| #1 | votingapi_views_handler_relationship.patch | 617 bytes | j_ten_man |
Comments
Comment #1
j_ten_man commentedHere 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.
Comment #2
eaton commentedCommitted to the dev branch, will be rolled into the next release. Thanks!
Comment #4
Royce-1 commentedThis 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
Comment #5
akalyptos commentedΤhis patch has taken three days of my life.
I have two content types. "products" and "shops".
"shops" can be voted with fivestar and "products" have a node reference for "shops".
I've created a view that is show the product and is use a relationship with the shop node reference to show the shop name and the average vote for shop.
Νothing worked and views query did a loop.
After I remove this patch everything works well.
Comment #6
j_ten_man commentedCan you post a copy of your view up (just in a text file is fine) so I can take a look at it? Also a screenshot of the views ui would be helpful for the view itself.
Comment #7
akalyptos commentedif you want i can zip and send you all the drupal website.
Comment #8
legolasboDrupal 6 is no longer supported. Closing old issues to clean up the issue queue.
Please reopen and update this issue if this is still an issue in the D7 or D8 version.