Hey! Thanks for this lifesaver.

I'd really love to be able to Sort the view by the number of references a node has. Is that already possible?

Comments

markus_petrux’s picture

Category: feature » support
Status: Active » Fixed

I do not see how this feature is related to this particular module. This is probably something to explore with Views GroupBy module, or another module that could provide such a feature.

PS: As a f.r. this would be "won't fix", but then the issue is not visible in default issues queue view. So, I'm switching to s.r. and marking it as fixed.

entendu’s picture

I may not have explained myself well.

Consider the following scenario: You have two node types, Questions and Answers. Answers reference the Questions they answer. You want to create a view of Most Answered Questions.

Since your view needs to output the Question node title, you use this module to create a relationship, and under filters in the view, filter on reverse nodereference > 0.

However, you cannot SORT by the # of nodereferences. That's what I'm looking to do, and this seems like the natural place to do it.

markus_petrux’s picture

Category: support » feature
Status: Fixed » Closed (won't fix)

Ok, so this is clearly a "feature request", so it ends up as "won't fix", or it could also be "by design".

To sort in Views, we use sort handlers. This is not related at all with this module. This module implements a Views relationship handler. That's the scope of this module.

If you need to sort by something that's not covered in Views, then you need to develop a sort handler. That's out of the scope of this module.

entendu’s picture

For anyone else looking to do the same, I solved it with hook_views_query_alter():

/**
* Implementation of hook_views_query_alter().
* Sorts the most viewed view by number of answers.
*/

function mymodule_views_query_alter(&$view, &$query) {
  if($view->name == "5_Most_Viewed") {
    $query->groupby[] = "node_node_data_field_question_node_data_field_question.field_question_nid";
    array_unshift($query->orderby, "count(node_node_data_field_question_node_data_field_question.field_question_nid) DESC");
  }
}