0

I'm trying to implement a "rating" system with Relation module. I have a Relation Type defined from a user --> node. The Relation Type has an Integer field to hold the rating.

I want to produce a view that shows the number of ratings and average rating. To start, I created a view with a list of nodes. I previously created a few "rating" relations between users and the nodes in the view, which can be seen in the Relations tab in content.

In views UI Advanced section, I added the Relationship from the node to its Relation. I added a view field for the Integer field on the Relation.

The label for the rating field shows, but the number is empty, even for relations I know are there.

Here is an export of the view:

$view = new view();
$view->name = 'offer_ratings';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Offer Ratings';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Offer Ratings';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '100';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Relationship: Content: Relation: rated by (node → relation) */
$handler->display->display_options['relationships']['relation_base_right_rated']['id'] = 'relation_base_right_rated';
$handler->display->display_options['relationships']['relation_base_right_rated']['table'] = 'node';
$handler->display->display_options['relationships']['relation_base_right_rated']['field'] = 'relation_base_right_rated';
$handler->display->display_options['relationships']['relation_base_right_rated']['r_index'] = '1';
$handler->display->display_options['relationships']['relation_base_right_rated']['entity_deduplication_right'] = 0;
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Field: Relation: Rating */
$handler->display->display_options['fields']['field_rating']['id'] = 'field_rating';
$handler->display->display_options['fields']['field_rating']['table'] = 'field_data_field_rating';
$handler->display->display_options['fields']['field_rating']['field'] = 'field_rating';
$handler->display->display_options['fields']['field_rating']['relationship'] = 'relation_base_right_rated';
$handler->display->display_options['fields']['field_rating']['settings'] = array(
  'thousand_separator' => '',
  'prefix_suffix' => 1,
);
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Content: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'offer' => 'offer',
);

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'offer-ratings';
1
  • I recommend doing this with EntityReference fields. I rebuilt the rating system by creating a "Rating" content type with a field that can relate it to my nodes. I can show rating stats in Views fields now. Commented Jul 30, 2013 at 17:40

1 Answer 1

0

Joe,

The best way to do a rating system in Drupal is to use Five Star: https://drupal.org/project/fivestar.

It comes with views integration out of the box. You add a rating field to your content type, place it in the display, render your entity in a view, or create a fielded view if you prefer the Drupal 6 way, and you're done.

1
  • Five Star is a great rating module, but the question is trying to solve a problem with the Relation module. I'm building the rating this way because my app will use a similar relationship to track "shares" "views" and other types of things too. Also, I'm creating the relationships with Services so the widget capability of Five Star isn't necessary. Commented Jul 31, 2013 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.