I'm trying to use the reverse relationship, i.e. "Entity with the @field (@field_name)". However, it doesn't seem to get the data.

Looking at the query data, the table it's trying to join with is field_data_@field_name. However, when I look at that table, it has no data in it. However, there is a table called field_data_@field_name_collection that has the same fields in it and does have data. Is this a bug or is there some sort of simple Views thing that I'm missing? Thanks!

Comments

dandaman’s picture

Also, when a view based on a field collection is created, using this back reference to the node will allow you to access the node's nid and other basic information but all of the fields are blank. See this example view below:

$view = new view;
$view->name = 'test_view';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'field_collection_item';
$view->human_name = 'test_view';
$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'] = 'test_view';
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$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: Field collection item: Entity with the Student (field_student) */
$handler->display->display_options['relationships']['field_student_node']['id'] = 'field_student_node';
$handler->display->display_options['relationships']['field_student_node']['table'] = 'field_collection_item';
$handler->display->display_options['relationships']['field_student_node']['field'] = 'field_student_node';
$handler->display->display_options['relationships']['field_student_node']['label'] = 'Node';
$handler->display->display_options['relationships']['field_student_node']['required'] = 1;
/* Field: Field collection item: Field collection item ID */
$handler->display->display_options['fields']['item_id']['id'] = 'item_id';
$handler->display->display_options['fields']['item_id']['table'] = 'field_collection_item';
$handler->display->display_options['fields']['item_id']['field'] = 'item_id';
/* Field: Content: Availability Notes */
$handler->display->display_options['fields']['field_availability_notes']['id'] = 'field_availability_notes';
$handler->display->display_options['fields']['field_availability_notes']['table'] = 'field_data_field_availability_notes';
$handler->display->display_options['fields']['field_availability_notes']['field'] = 'field_availability_notes';
$handler->display->display_options['fields']['field_availability_notes']['relationship'] = 'field_student_node';
/* Field: Content: Name(s) of doorkeeper(s) */
$handler->display->display_options['fields']['field_name_doorkeepers']['id'] = 'field_name_doorkeepers';
$handler->display->display_options['fields']['field_name_doorkeepers']['table'] = 'field_data_field_name_doorkeepers';
$handler->display->display_options['fields']['field_name_doorkeepers']['field'] = 'field_name_doorkeepers';
$handler->display->display_options['fields']['field_name_doorkeepers']['relationship'] = 'field_student_node';
$handler->display->display_options['fields']['field_name_doorkeepers']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['field_name_doorkeepers']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['field_name_doorkeepers']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['field_name_doorkeepers']['alter']['external'] = 0;
$handler->display->display_options['fields']['field_name_doorkeepers']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['field_name_doorkeepers']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['field_name_doorkeepers']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['field_name_doorkeepers']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['field_name_doorkeepers']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['field_name_doorkeepers']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['field_name_doorkeepers']['alter']['trim'] = 0;
$handler->display->display_options['fields']['field_name_doorkeepers']['alter']['html'] = 0;
$handler->display->display_options['fields']['field_name_doorkeepers']['element_label_colon'] = 1;
$handler->display->display_options['fields']['field_name_doorkeepers']['element_default_classes'] = 1;
$handler->display->display_options['fields']['field_name_doorkeepers']['hide_empty'] = 0;
$handler->display->display_options['fields']['field_name_doorkeepers']['empty_zero'] = 0;
$handler->display->display_options['fields']['field_name_doorkeepers']['hide_alter_empty'] = 1;
$handler->display->display_options['fields']['field_name_doorkeepers']['group_rows'] = 1;
$handler->display->display_options['fields']['field_name_doorkeepers']['delta_offset'] = '0';
$handler->display->display_options['fields']['field_name_doorkeepers']['delta_reversed'] = 0;
$handler->display->display_options['fields']['field_name_doorkeepers']['delta_first_last'] = 0;
$handler->display->display_options['fields']['field_name_doorkeepers']['field_api_classes'] = 0;
/* Field: Content: Nid */
$handler->display->display_options['fields']['nid']['id'] = 'nid';
$handler->display->display_options['fields']['nid']['table'] = 'node';
$handler->display->display_options['fields']['nid']['field'] = 'nid';
$handler->display->display_options['fields']['nid']['relationship'] = 'field_student_node';
$handler->display->display_options['fields']['nid']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['nid']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['nid']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['nid']['alter']['external'] = 0;
$handler->display->display_options['fields']['nid']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['nid']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['nid']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['nid']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['nid']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['nid']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['nid']['alter']['trim'] = 0;
$handler->display->display_options['fields']['nid']['alter']['html'] = 0;
$handler->display->display_options['fields']['nid']['element_label_colon'] = 1;
$handler->display->display_options['fields']['nid']['element_default_classes'] = 1;
$handler->display->display_options['fields']['nid']['hide_empty'] = 0;
$handler->display->display_options['fields']['nid']['empty_zero'] = 0;
$handler->display->display_options['fields']['nid']['hide_alter_empty'] = 1;
$handler->display->display_options['fields']['nid']['link_to_node'] = 0;
/* Field: Content: Number of all-day doorkeepers */
$handler->display->display_options['fields']['field_num_doorkeepers']['id'] = 'field_num_doorkeepers';
$handler->display->display_options['fields']['field_num_doorkeepers']['table'] = 'field_data_field_num_doorkeepers';
$handler->display->display_options['fields']['field_num_doorkeepers']['field'] = 'field_num_doorkeepers';
$handler->display->display_options['fields']['field_num_doorkeepers']['relationship'] = 'field_student_node';
$handler->display->display_options['fields']['field_num_doorkeepers']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['field_num_doorkeepers']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['field_num_doorkeepers']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['field_num_doorkeepers']['alter']['external'] = 0;
$handler->display->display_options['fields']['field_num_doorkeepers']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['field_num_doorkeepers']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['field_num_doorkeepers']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['field_num_doorkeepers']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['field_num_doorkeepers']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['field_num_doorkeepers']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['field_num_doorkeepers']['alter']['trim'] = 0;
$handler->display->display_options['fields']['field_num_doorkeepers']['alter']['html'] = 0;
$handler->display->display_options['fields']['field_num_doorkeepers']['element_label_colon'] = 1;
$handler->display->display_options['fields']['field_num_doorkeepers']['element_default_classes'] = 1;
$handler->display->display_options['fields']['field_num_doorkeepers']['hide_empty'] = 0;
$handler->display->display_options['fields']['field_num_doorkeepers']['empty_zero'] = 0;
$handler->display->display_options['fields']['field_num_doorkeepers']['hide_alter_empty'] = 1;
$handler->display->display_options['fields']['field_num_doorkeepers']['settings'] = array(
  'thousand_separator' => ' ',
  'prefix_suffix' => 1,
);
$handler->display->display_options['fields']['field_num_doorkeepers']['field_api_classes'] = 0;

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'test-view';
dandaman’s picture

Title: Reverse entity Views relationship not working » Reverse entity Views relationship not associating with node field data

I updated the title to better describe the issue. Basically, listing Field Collection data in a view and referencing the nodes that include the field collection allow you to access the basic data of a node, but the node's data that are in fields just show up as blank.

dandaman’s picture

This is something that helped me get the relationship working at all.

tim.plunkett’s picture

Status: Active » Needs review

Marking 'needs review' since there is a patch.

Status: Needs review » Needs work

The last submitted patch, 1379008-field-collection-relationship.patch, failed testing.

dandaman’s picture

Status: Needs work » Needs review
StatusFileSize
new920 bytes

OK, attempted uploading it again for review... this at least gets a relationship working from a Field Collection to a Node, although it sill has the problem of fields not being able to be related, for some reason.

blackandcode’s picture

tirdadc’s picture

StatusFileSize
new759 bytes

That patch doesn't work as far as the table name goes:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'blabla_db.field_data_field_collection_gallery_collection' doesn't exist

Once you fix the table name by removing the _collection at the end, you get:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'field_collection_item_field_data_field_collection_gallery__field_data_field_collection_gallery.field_collection_gallery_collection_value' in 'on clause'

so you need to fix that by also removing the _collection there for the column name (which is how it was before the patch).

Once the SQL errors are gone, it still doesn't function when I require the relationship (I can't get my relationship to force the view to list only recent files that were uploaded through a "gallery collection field > file field" in this case).

tim.plunkett’s picture

Status: Needs review » Needs work

Well there is no point to #4, as that is exactly what _field_sql_storage_tablename does for non-deleted fields anyway.

I've not had this problem, can you add exact steps to reproduce?

dandaman’s picture

Status: Needs work » Closed (cannot reproduce)

Tim,

I was having troubles with this on my local machine during development, but then when I moved it to staging it no longer had this problem. So I'm not sure what the problem is and, to the extent I need it, it is fixed. Thanks for your help.

dvega’s picture

Status: Closed (cannot reproduce) » Needs review

#8: 1379008-field-collection-relationship-8.patch queued for re-testing.

I still cannot relate the field collection with a node...

jsheffers’s picture

Has anyone been able to successfully do this?

kaizerking’s picture

this still is a bug
we cannot related a field collection field to node.
I tried using views cross join module as work around,even that doesn't work as views cross join is joins at item_id, what we need is join at field name.
can some one patch plz

nodecode’s picture

Status: Needs review » Active

The patch appears to do nothing to solve the problem...

@tim.plunkett
Here are the steps to reproduce:

1. Install Entity API 7.x-1.1, Entity Reference 7.x-1.0
2. Add a field collection field field_my_field_collection to the Article the content type
3. Add an entity reference field field_related_content to the field collection you just created
4. Import the view below. Note that it contains the relationship "A bridge to the Field collection item entity that is referencing Content via field_related_content"
5. While in the Views UI, click on the Title field and notice that there is no option to select a relationship (i.e. we cannot get the title of the referencing entity).

$view = new view();
$view->name = 'field_collection_bridge_example';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Field Collection Bridge Example';
$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'] = 'Field Collection Bridge Example';
$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'] = 'some';
$handler->display->display_options['pager']['options']['items_per_page'] = '5';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Relationship: Entity Reference: Referencing entity */
$handler->display->display_options['relationships']['reverse_field_related_content_field_collection_item']['id'] = 'reverse_field_related_content_field_collection_item';
$handler->display->display_options['relationships']['reverse_field_related_content_field_collection_item']['table'] = 'node';
$handler->display->display_options['relationships']['reverse_field_related_content_field_collection_item']['field'] = 'reverse_field_related_content_field_collection_item';
/* 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;
/* 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;

/* Display: Block */
$handler = $view->new_display('block', 'Block', 'block');
melchior’s picture

Issue summary: View changes

any fix? :(

AhmadZain’s picture

Try to check this one it may help.
https://www.drupal.org/node/2010642