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')

Comments

ff1’s picture

I 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

ff1’s picture

After taking a closer look at the SQL generated, I have spotted where the error is. The SQL should look like this:

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_node_data_field_contact__node_data_field_telephone.field_telephone_value AS node_node_data_field_contact__node_data_field_telephone_field_telephone_value,
   node_node_data_field_contact__node_data_field_telephone.nid AS node_node_data_field_contact__node_data_field_telephone_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_node_data_field_contact__node_data_field_telephone ON node_node_data_field_contact.vid = node_node_data_field_contact__node_data_field_telephone.vid
 WHERE node.type in ('property')

However, I have no idea where this error is introduced. Can anyone point me in the right direction?

ff1’s picture

Project: Content Construction Kit (CCK) » Views (for Drupal 7)
Version: 6.x-2.0-rc4 » 6.x-2.0-rc1
Component: Views Integration » node data

This 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

merlinofchaos’s picture

Hmmm. 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?

ff1’s picture

Adding an email field produced another empty column with the following 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,
   node_data_field_job_title.field_email_address_value AS node_data_field_job_title_field_email_address_value
 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')

Re-arranging the fields changed things so that telephone number was populated, but job title and email address were blank. New SQL shown below:

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_telephone.field_telephone_value AS node_node_data_field_contact__node_data_field_telephone_field_telephone_value,
   node_node_data_field_contact__node_data_field_telephone.nid AS node_node_data_field_contact__node_data_field_telephone_nid,
   node_data_field_telephone.field_job_title_value AS node_data_field_telephone_field_job_title_value,
   node_data_field_telephone.nid AS node_data_field_telephone_nid,
   node_data_field_telephone.field_email_address_value AS node_data_field_telephone_field_email_address_value
 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_telephone ON node_node_data_field_contact.vid = node_node_data_field_contact__node_data_field_telephone.vid
 LEFT JOIN content_type_contact node_data_field_telephone ON node.vid = node_data_field_telephone.vid
 WHERE node.type in ('property')

I hope that helps you get to the bottom of this. :)

ff1’s picture

Adding 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.

Jeffdo’s picture

I'm experiencing the same behaviour with an identical scenario.

merlinofchaos’s picture

Priority: Normal » Critical

You don't see me do this every day. =)

ff1’s picture

Wow! :)

Let me know if I can do anything to help resolve this issue.

Jeffdo’s picture

Each stubbornly missing field will appear in the view if you add it as an 'existing' field to another (CCK) content type.

shaman365’s picture

Hello! 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!

ff1’s picture

As 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:

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,
   node_node_data_field_contact__node_data_field_email_address.field_email_address_value AS node_node_data_field_contact__node_data_field_email_address_field_email_address_value,
   node_node_data_field_contact__node_data_field_email_address.nid AS node_node_data_field_contact__node_data_field_email_address_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
 LEFT JOIN content_field_email_address node_node_data_field_contact__node_data_field_email_address ON node_node_data_field_contact.vid = node_node_data_field_contact__node_data_field_email_address.vid
 WHERE node.type in ('property')
shaman365’s picture

I 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

Crell’s picture

I 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:

SELECT ...
 FROM node node 
 LEFT JOIN content_type_project node_data_field_supportstatus ON node.vid = node_data_field_supportstatus.vid
 INNER JOIN node node_node_data_field_supportstatus ON node_data_field_supportstatus.field_supportstatus_nid = node_node_data_field_supportstatus.nid
 LEFT JOIN node node_node_data_field_client ON .field_client_nid = node_node_data_field_client.nid
 LEFT JOIN term_node term_node ON node.vid = term_node.vid
 LEFT JOIN term_data term_data ON term_node.tid = term_data.tid

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:

SELECT ...
 FROM node node 
 LEFT JOIN content_type_project node_data_field_client ON node.vid = node_data_field_client.vid
 LEFT JOIN node node_node_data_field_client ON node_data_field_client.field_client_nid = node_node_data_field_client.nid
 INNER JOIN node node_node_data_field_supportstatus ON node_data_field_supportstatus.field_supportstatus_nid = node_node_data_field_supportstatus.nid
 LEFT JOIN term_node term_node ON node.vid = term_node.vid
 LEFT JOIN term_data term_data ON term_node.tid = term_data.tid
 INNER JOIN content_type_project node_data_field_supportstatus ON node.vid = node_data_field_supportstatus.vid

If either relation is present and is the only relation, there is no error.

merlinofchaos’s picture

Ok, 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.

merlinofchaos’s picture

Status: Active » Fixed
StatusFileSize
new2.43 KB

Found it!!!!

I committed the fix, but for those of you who want to play right now, a patch is attached.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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