0

I have a Field Collection field in a node. The field collection has two fields, so I can associate a group of paired values to a node. For example, {a,1}, {b,2},{c,3},{d,4}.

I have a View in which I want to filter by the values above. If I use a filter for the first type of values and put a, it will return the first 2-tuple. If I put 2 in the second filter (and nothing in first filter), it will return the second 2-tuple. But if I look for c in first filter and 4 in the second filter simoultaneously, it will return the 2 last values, because c matches the condition and 4 matches the condition, separatedly. How can I make the View filter so I get the desired result, which is empty result in this case?

1

I am not able to reproduce the behavior you describe. In configuring a Field Collections and Views in the way you describe I do get the desired results.

Here is a screenshot of my configuration:

View config

And here are the results:

View results

And here is the filtering:

By letter:

Filtering letter

By number:

enter image description here

Mismatched letter/number yields no results:

enter image description here

And here is the full View export:

$view = new view();
$view->name = 'stacktest_fieldcollection';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'stacktest_fieldcollection';
$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'] = 'stacktest_fieldcollection';
$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'] = '10';
$handler->display->display_options['style_plugin'] = 'table';
/* Relationship: Content: FC (field_fc) */
$handler->display->display_options['relationships']['field_fc_value']['id'] = 'field_fc_value';
$handler->display->display_options['relationships']['field_fc_value']['table'] = 'field_data_field_fc';
$handler->display->display_options['relationships']['field_fc_value']['field'] = 'field_fc_value';
$handler->display->display_options['relationships']['field_fc_value']['required'] = TRUE;
$handler->display->display_options['relationships']['field_fc_value']['delta'] = '-1';
/* 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']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Field: Field collection item: Letter */
$handler->display->display_options['fields']['field_letter']['id'] = 'field_letter';
$handler->display->display_options['fields']['field_letter']['table'] = 'field_data_field_letter';
$handler->display->display_options['fields']['field_letter']['field'] = 'field_letter';
$handler->display->display_options['fields']['field_letter']['relationship'] = 'field_fc_value';
/* Field: Field collection item: Number */
$handler->display->display_options['fields']['field_number']['id'] = 'field_number';
$handler->display->display_options['fields']['field_number']['table'] = 'field_data_field_number';
$handler->display->display_options['fields']['field_number']['field'] = 'field_number';
$handler->display->display_options['fields']['field_number']['relationship'] = 'field_fc_value';
/* 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';
/* Contextual filter: Field collection item: Letter (field_letter) */
$handler->display->display_options['arguments']['field_letter_value']['id'] = 'field_letter_value';
$handler->display->display_options['arguments']['field_letter_value']['table'] = 'field_data_field_letter';
$handler->display->display_options['arguments']['field_letter_value']['field'] = 'field_letter_value';
$handler->display->display_options['arguments']['field_letter_value']['relationship'] = 'field_fc_value';
$handler->display->display_options['arguments']['field_letter_value']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['field_letter_value']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['field_letter_value']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['field_letter_value']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['field_letter_value']['limit'] = '0';
/* Contextual filter: Field collection item: Number (field_number) */
$handler->display->display_options['arguments']['field_number_value']['id'] = 'field_number_value';
$handler->display->display_options['arguments']['field_number_value']['table'] = 'field_data_field_number';
$handler->display->display_options['arguments']['field_number_value']['field'] = 'field_number_value';
$handler->display->display_options['arguments']['field_number_value']['relationship'] = 'field_fc_value';
$handler->display->display_options['arguments']['field_number_value']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['field_number_value']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['field_number_value']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['field_number_value']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['field_number_value']['limit'] = '0';
/* 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;

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'stacktest-fieldcollection';
  • I think that the solution is to require the relationship in both relations. That may be the difference and explains why I yield results. Once the relationship is established, the Require relationship forces a INNER JOIN which makes the related content unique. – Cesar Nov 24 '15 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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