I have a view that displays all 'parent' nodes referenced from 'child' nodes. I just want to list the titles of the referenced nodes, but because there can be multiple 'child' nodes referencing the parent nodes, my view displays the 'parent' node titles multiple times (depending on how many child nodes refer to the parent).
I was trying to use Views 3.x's new 'Grouping' feature to group all nodes by nid, but that didn't seem to make a difference. I tried using an nid that was grouped in the filters section, and an nid that was grouped in the fields section, but it didn't matter.
I could do a views_pre_render and just remove the duplicates manually, but that's messy, and would also screw up the pager. (See here for something along those lines: http://capellic.com/blog/cure-duplicate-nodes-in-a-view).
Is there a better way to do this, or something I'm overlooking?
I also tried using the following hook_views_query_alter() hook:
/**
* Implements hook_views_query_alter().
*/
function custom_views_query_alter(&$view, &$query) {
if ($view->name == 'my_subscriptions' && $view->current_display == 'my_networks') {
$query->groupby[] = 'node_field_data_field_list_network_nid';
}
}
But still no dice...
Here's the query being generated by views:
SELECT DISTINCT node_field_data_field_list_network.nid AS node_field_data_field_list_network_nid, node_field_data_field_list_network.title AS node_field_data_field_list_network_title, node.title AS node_title, node.nid AS nid FROM {node} node INNER JOIN {flag_content} flag_content_node ON node.nid = flag_content_node.content_id AND (flag_content_node.fid = :views_join_condition_0 AND flag_content_node.uid = :views_join_condition_1) LEFT JOIN {field_data_field_list_network} field_data_field_list_network ON node.nid = field_data_field_list_network.entity_id AND (field_data_field_list_network.entity_type = :views_join_condition_2 AND field_data_field_list_network.deleted = :views_join_condition_3) INNER JOIN {node} node_field_data_field_list_network ON field_data_field_list_network.field_list_network_nid = node_field_data_field_list_network.nid INNER JOIN {users} users ON node.uid = users.uid WHERE (( (node.status = '1') AND (node_field_data_field_list_network.type IN ('network')) AND (users.uid = '1' ) )) ORDER BY node_title DESC LIMIT 3 OFFSET 0