Hi!

I have developed and currently maintaining the Nodefeedback module. It uses VotingAPI to store the answers to the questions as option voting.

The issue is that VotingAPI aggregation function names the function as option-0, option-1, etc. - using the hyphen "-" in the name. Then, using hook_votingapi_metadata_alter(), I'm describing the aggregation function:

  $data['functions']['option-0'] = array(
    'name' => t('Number of answers "Yes" (0)'),
    'description' => t('Some description.'),
    'module' => 'nodefeedback',
  );

And when adding relationship I'm choosing the aggregation function described above. After adding a value of this function to the Views column - the generated query can't be executed and Views automatically adds:

LEFT JOIN votingapi_cache votingapi_cache_node_points_resolution_option-0 ON node.nid = votingapi_cache_node_points_resolution_option-0.content_id AND (votingapi_cache_node_points_resolution_option-0.content_type = 'node' AND votingapi_cache_node_points_resolution_option-0.value_type = 'points' AND votingapi_cache_node_points_resolution_option-0.tag = 'resolution' AND votingapi_cache_node_points_resolution_option-0.function = 'option-0')

which is not a valid MySQL (as it has hyphens in the table alias).

Hope you can help here. The obvious fix for it would be changing the hyphen to the underscore symbol "_", but then we need to figure out updating of all the already calculated aggregations.

Thanks
AndyB

CommentFileSizeAuthor
#1 937998.patch481 bytesmauritsl
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mauritsl’s picture

Title: Option voting aggregation function Views query builder compatibility » SQL error when using aggregate function "option-1" in relationships
Component: Code » Views Integration
Status: Active » Needs review
FileSize
481 bytes

Got the same error.

The alias is generated by the votingapi module itself. A simple preg_replace can fix the problem. The patch attached fixed this problem for me (at least for 2.3).

mauritsl’s picture

A usecase and view export is available at #960438: Sorting by "options" results seems to be broken.

vikstrous’s picture

Thank you! I was having the same problem. This seems like the best solution to me. I don't know why it wasn't done earlier.

eaton’s picture

I've made this fix to the D7 version and will be backporting it as soon as the D7 release is out. Thanks!

legolasbo’s picture

Status: Needs review » Closed (won't fix)

Drupal 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.