I'm not sure where this bug originates, so I apologise if it turns out to be a views issue.
My basic problem is that only one field is ever displayed when I use a nodereference relationship in a view. Here is my scenario:
I have 2 simple content types: Property and Contact (both setup specifically to test the nodereference relationship). A property is a site or building and a contact is an employee.
Contacts have 2 text fields: Job title and telephone number.
Properties have 1 text field: Town, and 1 nodereference field: Contacts (which allows for unlimted selections).
I want a view that lists all of the contacts (including job title and telephone number) for a specific property. This view is intended to appear as a block on each property page.
I created a 'Node' view, filtered by 'Node type = Property'. I added a relationship using the 'Content: Node reference: Contact' field. I then added a field for 'Node title' without selecting any relationship. I then added fields for 'Node title', 'Job title' and 'Telephone number', each using the relationship created previously. I understand that this view will list all properties, but I will add an argument for the specific property when I get this bit working.
See the attached screenshot for details of this view. As you can see from preview in this attachment, the Job title field is populated, but the telephone number field is not. This is the problem.
Any help would be greatly appreciated.
Full details of the content types, view and generated sql are shown below:
Content type - Contact:
$content[type] = array (
'name' => 'Contact',
'type' => 'contact',
'description' => 'Stores contact details for employees.',
'title_label' => 'Name',
'body_label' => '',
'min_word_count' => '0',
'help' => '',
'node_options' =>
array (
'status' => true,
'promote' => true,
'sticky' => false,
'revision' => false,
),
'old_type' => 'contact',
'orig_type' => '',
'module' => 'node',
'custom' => '1',
'modified' => '1',
'locked' => '0',
'comment' => 2,
'comment_default_mode' => 4,
'comment_default_order' => 1,
'comment_default_per_page' => 50,
'comment_controls' => 3,
'comment_anonymous' => 0,
'comment_subject_field' => 1,
'comment_preview' => 1,
'comment_form_location' => 0,
);
$content[fields] = array (
0 =>
array (
'label' => 'Job title',
'field_name' => 'field_job_title',
'type' => 'text',
'widget_type' => 'text_textfield',
'change' => 'Change basic information',
'weight' => '-4',
'rows' => 1,
'description' => '',
'default_value_widget' =>
array (
'field_job_title' =>
array (
0 =>
array (
'value' => '',
'_error_element' => 'default_value_widget][field_job_title][0][value',
),
),
),
'default_value_php' => '',
'group' => false,
'required' => '1',
'multiple' => '0',
'text_processing' => '0',
'max_length' => '',
'allowed_values' => '',
'allowed_values_php' => '',
'module' => 'text',
'widget_module' => 'text',
'columns' =>
array (
'value' =>
array (
'type' => 'text',
'size' => 'big',
'not null' => false,
'sortable' => true,
),
),
'default_value' =>
array (
0 =>
array (
'value' => '',
'_error_element' => 'default_value_widget][field_job_title][0][value',
),
),
'display_settings' =>
array (
'label' =>
array (
'format' => 'above',
),
'teaser' =>
array (
'format' => 'default',
),
'full' =>
array (
'format' => 'default',
),
4 =>
array (
'format' => 'default',
),
),
),
1 =>
array (
'label' => 'Telephone number',
'field_name' => 'field_telephone',
'type' => 'text',
'widget_type' => 'text_textfield',
'change' => 'Change basic information',
'weight' => '-3',
'rows' => 1,
'description' => '',
'default_value_widget' =>
array (
'field_telephone' =>
array (
0 =>
array (
'value' => '',
'_error_element' => 'default_value_widget][field_telephone][0][value',
),
),
),
'default_value_php' => '',
'group' => false,
'required' => '1',
'multiple' => '0',
'text_processing' => '0',
'max_length' => '18',
'allowed_values' => '',
'allowed_values_php' => '',
'module' => 'text',
'widget_module' => 'text',
'columns' =>
array (
'value' =>
array (
'type' => 'varchar',
'length' => '18',
'not null' => false,
'sortable' => true,
),
),
'display_settings' =>
array (
'label' =>
array (
'format' => 'above',
),
'teaser' =>
array (
'format' => 'default',
),
'full' =>
array (
'format' => 'default',
),
4 =>
array (
'format' => 'default',
),
),
),
);
Content type - Property:
$content[type] = array (
'name' => 'Property',
'type' => 'property',
'description' => 'Stores general information about owned or rented properties.',
'title_label' => 'Property name',
'body_label' => '',
'min_word_count' => '0',
'help' => '',
'node_options' =>
array (
'status' => true,
'promote' => true,
'sticky' => false,
'revision' => false,
),
'old_type' => 'property',
'orig_type' => '',
'module' => 'node',
'custom' => '1',
'modified' => '1',
'locked' => '0',
'comment' => 2,
'comment_default_mode' => 4,
'comment_default_order' => 1,
'comment_default_per_page' => 50,
'comment_controls' => 3,
'comment_anonymous' => 0,
'comment_subject_field' => 1,
'comment_preview' => 1,
'comment_form_location' => 0,
);
$content[fields] = array (
0 =>
array (
'label' => 'Town',
'field_name' => 'field_address_town',
'type' => 'text',
'widget_type' => 'text_textfield',
'change' => 'Change basic information',
'weight' => '-4',
'rows' => 1,
'description' => '',
'default_value_widget' =>
array (
'field_address_town' =>
array (
0 =>
array (
'value' => '',
'_error_element' => 'default_value_widget][field_address_town][0][value',
),
),
),
'default_value_php' => '',
'group' => false,
'required' => '1',
'multiple' => '0',
'text_processing' => '0',
'max_length' => '64',
'allowed_values' => '',
'allowed_values_php' => '',
'module' => 'text',
'widget_module' => 'text',
'columns' =>
array (
'value' =>
array (
'type' => 'varchar',
'length' => '64',
'not null' => false,
'sortable' => true,
),
),
'default_value' =>
array (
0 =>
array (
'value' => '',
'_error_element' => 'default_value_widget][field_address_town][0][value',
),
),
'display_settings' =>
array (
'label' =>
array (
'format' => 'above',
),
'teaser' =>
array (
'format' => 'default',
),
'full' =>
array (
'format' => 'default',
),
4 =>
array (
'format' => 'default',
),
),
),
1 =>
array (
'label' => 'Contacts',
'field_name' => 'field_contact',
'type' => 'nodereference',
'widget_type' => 'nodereference_autocomplete',
'change' => 'Change basic information',
'weight' => '-3',
'description' => '',
'default_value_widget' =>
array (
'field_contact' =>
array (
0 =>
array (
'nid' =>
array (
'nid' => '',
'_error_element' => 'default_value_widget][field_contact][0][nid][nid',
),
'_error_element' => 'default_value_widget][field_contact][0][nid][nid',
),
),
),
'default_value_php' => '',
'group' => false,
'required' => '0',
'multiple' => '1',
'referenceable_types' =>
array (
'contact' => true,
0 => 1,
'page' => false,
'property' => false,
'story' => false,
),
'advanced_view' => '--',
'advanced_view_args' => '',
'module' => 'nodereference',
'widget_module' => 'nodereference',
'columns' =>
array (
'nid' =>
array (
'type' => 'int',
'unsigned' => true,
'not null' => false,
),
),
'display_settings' =>
array (
'label' =>
array (
'format' => 'above',
),
'teaser' =>
array (
'format' => 'default',
),
'full' =>
array (
'format' => 'default',
),
4 =>
array (
'format' => 'default',
),
),
),
);
View:
$view = new view;
$view->name = 'property_contact';
$view->description = 'Lists a users archived teams';
$view->tag = 'Contacts';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(
'field_contact_nid' => array(
'label' => 'field_contact_nid',
'required' => 0,
'id' => 'field_contact_nid',
'table' => 'node_data_field_contact',
'field' => 'field_contact_nid',
'relationship' => 'none',
),
));
$handler->override_option('fields', array(
'title_1' => array(
'label' => 'Property',
'link_to_node' => 0,
'exclude' => 0,
'id' => 'title_1',
'table' => 'node',
'field' => 'title',
'relationship' => 'none',
),
'title' => array(
'label' => 'Name',
'link_to_node' => 1,
'exclude' => 0,
'id' => 'title',
'table' => 'node',
'field' => 'title',
'relationship' => 'field_contact_nid',
),
'field_job_title_value' => array(
'label' => '',
'link_to_node' => 0,
'label_type' => 'widget',
'format' => 'default',
'multiple' => array(
'group' => TRUE,
'multiple_number' => '',
'multiple_from' => '',
'multiple_reversed' => FALSE,
),
'exclude' => 0,
'id' => 'field_job_title_value',
'table' => 'node_data_field_job_title',
'field' => 'field_job_title_value',
'relationship' => 'field_contact_nid',
),
'field_telephone_value' => array(
'label' => '',
'link_to_node' => 0,
'label_type' => 'widget',
'format' => 'default',
'multiple' => array(
'group' => TRUE,
'multiple_number' => '',
'multiple_from' => '',
'multiple_reversed' => FALSE,
),
'exclude' => 0,
'id' => 'field_telephone_value',
'table' => 'node_data_field_telephone',
'field' => 'field_telephone_value',
'relationship' => 'field_contact_nid',
),
));
$handler->override_option('filters', array(
'type' => array(
'operator' => 'in',
'value' => array(
'property' => 'property',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
),
));
$handler->override_option('access', array(
'type' => 'none',
'role' => array(),
'perm' => '',
));
$handler->override_option('style_plugin', 'table');
SQL:
SELECT node.nid AS nid,
node.title AS node_title,
node_node_data_field_contact.title AS node_node_data_field_contact_title,
node_node_data_field_contact.nid AS node_node_data_field_contact_nid,
node.type AS node_type,
node_node_data_field_contact__node_data_field_job_title.field_job_title_value AS node_node_data_field_contact__node_data_field_job_title_field_job_title_value,
node_node_data_field_contact__node_data_field_job_title.nid AS node_node_data_field_contact__node_data_field_job_title_nid,
node_data_field_job_title.field_telephone_value AS node_data_field_job_title_field_telephone_value,
node_data_field_job_title.nid AS node_data_field_job_title_nid
FROM node node
LEFT JOIN content_field_contact node_data_field_contact ON node.vid = node_data_field_contact.vid
LEFT JOIN node node_node_data_field_contact ON node_data_field_contact.field_contact_nid = node_node_data_field_contact.nid
LEFT JOIN content_type_contact node_node_data_field_contact__node_data_field_job_title ON node_node_data_field_contact.vid = node_node_data_field_contact__node_data_field_job_title.vid
LEFT JOIN content_type_contact node_data_field_job_title ON node.vid = node_data_field_job_title.vid
WHERE node.type in ('property')
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | relationship.patch | 2.43 KB | merlinofchaos |
| cck-nodereference-relationship.jpg | 165.57 KB | ff1 |
Comments
Comment #1
ff1 commentedI have seen another issue #284898: Duplicate entries in Views due to relationship to a CCK field with multiple values and wonder whether mine falls into a similar category?
I think this sort of view would be a fairly common requirement, so if I can help in any way to get it working, then please let me know.
Ian
Comment #2
ff1 commentedAfter taking a closer look at the SQL generated, I have spotted where the error is. The SQL should look like this:
However, I have no idea where this error is introduced. Can anyone point me in the right direction?
Comment #3
ff1 commentedThis issue has had no response from the CCK issue queue, so I can only assume it is a views problem. I have therefore transferred it to the views issue queue.
Any help would be greatly appreciated.
Ian
Comment #4
merlinofchaos commentedHmmm. This is very odd. It's almost as though the telephone number is ignoring the relationship entirely.
Here's a question; if there are 2 or 3 other random fields in there, is this restricted to a particular field? Does rearranging the fields change which field gets added wrong? I'm curious to see if there is maybe an order issue here, or if it's specific to one field or field type, for example. Would you be able to explore this a little and see if you can find a commonality to what is breaking here?
Comment #5
ff1 commentedAdding an email field produced another empty column with the following SQL:
Re-arranging the fields changed things so that telephone number was populated, but job title and email address were blank. New SQL shown below:
I hope that helps you get to the bottom of this. :)
Comment #6
ff1 commentedAdding many other fields of all different types (decimal, node reference, etc.) yields the same results. The first field is displayed as expected and all other fields are blank.
Comment #7
Jeffdo commentedI'm experiencing the same behaviour with an identical scenario.
Comment #8
merlinofchaos commentedYou don't see me do this every day. =)
Comment #9
ff1 commentedWow! :)
Let me know if I can do anything to help resolve this issue.
Comment #10
Jeffdo commentedEach stubbornly missing field will appear in the view if you add it as an 'existing' field to another (CCK) content type.
Comment #11
shaman365 commentedHello! I don't know if I'm posting in the right area....but I think this is what I am trying to do too... I have a view that displays the nodes from a nodreference field and for the life of me I can't figure out how to have the nodes in the array show up as a non integer value. I basically need the actual node value to show up in the views service.
Here's how my view shows up in the views service:
[field_trackitem] => Array
(
[0] => Array
(
[nid] => 9
)
[1] => Array
(
[nid] => 12
)
)
I just need those [nid]'s to show that actual node values. I'm building an flash mp3 player application that collects this data from this view. I just can't figure this out. Any help is very appreciated. Sorry if this question is too noobish. I'm still new but very excited about building druplash type applications. Thanks!
Comment #12
ff1 commentedAs Jeffdo states in #10, adding the missing fields to another contact type makes them show up in the view. So, here is the SQL generated when I added the email address field to a new contact type and then previewed the view created in #5 above:
Comment #13
shaman365 commentedI tried that out and couldn't get it going.
The nodes show up fine in the preview in views. I see all of the content I have associated with my nodereference field which is called 'trackitem' that is filtered through 'visionmp3'. This node 'trackitem' references a node 'track' which holds the mp3 data, an image, and nodereferences to 'artist' and 'album' content.
Here's what the sql looks like in views:
SELECT node.nid AS nid,
node.type AS node_type,
node_data_field_trackitem.field_trackitem_nid AS node_data_field_trackitem_field_trackitem_nid,
node_data_field_trackitem.nid AS node_data_field_trackitem_nid,
node_data_field_visionmp3_autoplay.field_visionmp3_autoplay_value AS node_data_field_visionmp3_autoplay_field_visionmp3_autoplay_value,
node_data_field_visionmp3_autoplay.nid AS node_data_field_visionmp3_autoplay_nid
FROM node node
LEFT JOIN content_field_trackitem node_data_field_trackitem ON node.vid = node_data_field_trackitem.vid
LEFT JOIN content_type_visionmp3 node_data_field_visionmp3_autoplay ON node.vid = node_data_field_visionmp3_autoplay.vid
WHERE node.type in ('visionmp3')
Any other hints? I've been trying to get this view right for two days....If I can get this one going, It will open up so much more development for me. I'm trying to do something similar to: sony bmg nodereference blueprint
Comment #14
Crell commentedI have a related problem, I think. I am not adding multiple fields from one reference but multiple references. (Earl said to post it here in case it is related. :-) )
With one reference, it works fine. As soon as I add a second reference, however (both on different nodereference CCK fields), I get an SQL error. Specifically, I get a join clause like so:
LEFT JOIN node node_node_data_field_client ON .field_client_nid = node_node_data_field_client.nid
Full query:
However, when I reverse the order of the relations I get a different SQL error: "Unknown column 'node_data_field_supportstatus.field_supportstatus_nid'".
Query:
If either relation is present and is the only relation, there is no error.
Comment #15
merlinofchaos commentedOk, in my first checkin, I have a test view that I was using on relationships, and it encapsulates this scenario and more and for some reason, it is working even though the views presented here do not. I'm not sure why. I'm continuing to investigate, but at this time if someone has a test database they could give me that replicates this behavior, it might be easier for me to figure out what's wrong.
Comment #16
merlinofchaos commentedFound it!!!!
I committed the fix, but for those of you who want to play right now, a patch is attached.
Comment #17
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.