I have cck fields with multiple values. When I create a view, I select "group multiple values" handler for each cck field in the view. When I look at the executed view as admin, the cck field values are grouped correctly in each column. When I look at the view as any other user, I see the values in each field duplicated dozens of times.

Can someone help me figure out this problem? I've got CCK 5.x-1.4

Thanks!

Comments

merlinofchaos’s picture

Project: Views (for Drupal 7) » Content Construction Kit (CCK)
Version: 5.x-1.5 » 5.x-1.4
Component: Code » Views Integration

I don't know if CCK has addressed this yet or not, but multiple fields need special handling in order to deal with this problem. I know they're aware of the issue, and I suspect this will be marked duplicate when someone from CCK sees it and knows what to mark it a dup as.

SomebodySysop’s picture

Category: bug » feature

In my case at least, I assume I get this problem because I have a customized node_db_rewrite_sql and the "group multiple values" field handler (content_views_field_handler_group) calls db_rewrite_sql. I added one line to this handler, and it seems to have resolved my issue:

function content_views_field_handler_group($field_info, $field_data, $value, $data) {
  $field = $field_info['content_field'];
  $items = array();
  if ($field['multiple']) {
    foreach ($field_info['content_db_info']['columns'] as $column => $attributes) {
      $query_columns[] = "node_data_$field[field_name].$attributes[column] AS $column";
    }
    $query = "SELECT ".implode(', ', $query_columns).
             " FROM {node} node".
             " LEFT JOIN {". $field_info['content_db_info']['table'] ."} node_data_$field[field_name] ON node.vid = node_data_$field[field_name].vid".
             " WHERE node.nid = ".$data->nid.
             " ORDER BY node_data_$field[field_name].delta";
    $result = db_query(db_rewrite_sql($query, 'node'));
    while ($item = db_fetch_array($result)) {
      $items[] = content_format($field, $item, $field_data['options'], $data);
    }
	//
	// My Modification - Gets rid of duplicated array items.  My exact problem was duplicated array items.
	//
		$items = array_unique($items);

    return theme('content_view_multiple_field', $items, $field, $data);
  }
  else {
    return content_views_field_handler_ungroup($field_info, $field_data, $value, $data);
  }
}

Of course, I don't know if this is the best approach, whether it opens me up to other potential problems. Any comments?

If this is a good fix, could it be incorporated into the handler permanently (which is why I changed this issue to a feature request)?

Harry Slaughter’s picture

subscribing.

seeing this problem too. we're using 3 ACL modules. i'm wondering if ACL modules and the subsequent db_rewrite_sql that takes place is causing this.

Niel Jackob’s picture

Same problem, thanks for your solution. Now it is working.

derhasi’s picture

I have the same problem. In my case it appears when using nodeaccess oder content_access (ACL activated too). besides i use taxonomy_access. but that did not cause the problem.

Your array_unique works around the problem. I guess it is caused by some node_access restriction, forced by the above modules- but I cannot pinpoint it. I recognized some difference in the MySQL-query for the users, caused by content_views_field_handler_group, so perhaps it could help you:

Field_runden is a computed field with multiple values.

	#user 1
	SELECT node_data_field_runden.field_runden_value AS value
	FROM zp_node node 
	LEFT JOIN zp_content_field_runden node_data_field_runden ON node.vid = node_data_field_runden.vid
	WHERE node.nid = 19
	ORDER BY node_data_field_runden.delta
	#other user
	SELECT node_data_field_runden.field_runden_value AS value
	FROM zp_node node 
	LEFT JOIN zp_content_field_runden node_data_field_runden ON node.vid = node_data_field_runden.vid
	INNER JOIN zp_node_access na ON na.nid = node.nid
	WHERE (	na.grant_view >= 1
					AND ((na.gid = 0 AND na.realm = 'all')
						OR (na.gid = 3 AND na.realm = 'content_access_author')
						OR (na.gid = 2 AND na.realm = 'content_access_rid')
						OR (na.gid = 5 AND na.realm = 'content_access_rid')
						OR (na.gid = 2 AND na.realm = 'term_access')
						OR (na.gid = 5 AND na.realm = 'term_access'))
				)AND ( node.nid = 19 )
	ORDER BY node_data_field_runden.delta
yched’s picture

Status: Active » Fixed

fixed in latest 5.x-1.x : the db_rewrite_sql is not needed to begion with :-/ (we only retrieve nids selected by views' main query, which takes care of the db_rewrite_sql...)

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

Benjamin.chiao’s picture

Status: Closed (fixed) » Active

I still have the problem.

Sometimes each individual is shown multiple times in the search results. Those individuals are those that have multiple answers to questions of the multiple value types.
Yes, there is a "group multiple values" option in the fields options (when constructing the view), the values are grouped indeed but the whole entry listed multiple times in the search results.

Any ideas?

derhasi’s picture

Status: Active » Fixed

That is a matter by design, and not part of the original problem. To solve your problem simply select "Node:Distinct" in your views' filter. ;)

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.