1

Fields names are equal in both tables.

Inside hook_views_data:

  $data['stream']['table']['join'] = array(
    'node' => array(
      'left_field' => 'nid',
      'field' => 'nid',
    ),
  );

 $data['stream']['nid'] = array(
    'title' => t('Related node'),
    'help' => t('Node related to stream item.'),
    // Define a relationship to the {node} table, so example_table views can
    // add a relationship to nodes. If you want to define a relationship the
    // other direction, use hook_views_data_alter(), or use the 'implicit' join
    // method described above.
    'relationship' => array(
      'base' => 'node', // The name of the table to join with.
      'base field' => 'nid', // The name of the field on the joined table.
      'field' => 'nid',
      'handler' => 'views_handler_relationship',
      'label' => t('Default label for the relationship'),
      'title' => t('Title shown when adding the relationship'),
      'help' => t('More information on this relationship'),
    ),
  );

(similar to example from api page)

but there isn't above relation in Add relationships box. Could some one give me any hint?

1 Answer 1

1

I solved it by this way:

$data['stream']['table']['join'] = array(
  'node' => array(
    'left_field' => 'nid',
    'field' => 'nid',
    'handler' => 'views_join', // this is actually optional
    'left_table' => 'node'
  ),
);


$data['stream']['nid'] = array(
    'title' => t('Related node'),
    'help' => t('Node related to stream item.'),

    'field' => array(
      'handler' => 'views_handler_field_numeric',
      'click sortable' => TRUE,
    ),

    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
      'allow empty' => TRUE,
      'help' => 'Filter on a related node nid.',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
      'numeric' => TRUE,
      'validate type' => 'nid',
      'help' => 'Argument on related node nid.',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
      'help' => 'Sort on related node nid field.',
    ),
    'relationship' => array(
      'title' => t('Stream node'),
      'help' => t('Relation to node related to current stream item'),
      'label' => t('Stream node'),
      'base' => 'node',
      'base field' => 'nid',
    ),
  );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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