4

I have two tables activity and activity_map. I need to join both the tables by aid. Below is my code for hook_views_data. Base table is working fine including custom text handler. But I do not see the joined table(activity_map) fields (entity_id, entity_type) either in fields section nor in arguments or filters. Am I missing anything?

  <?php

    /**
 * Implements hook_views_data
 */
function activity_teamie_views_data() {
  $data['activity_teamie']['table']['group'] = t('Activity');
  $data['activity_teamie']['table']['base'] = array(
    'title' => t('Activity'),
    'field' => 'aid',
    'help' => t('Activity feed item')
  );
  $data['activity_teamie']['aid'] = array(
    'title' => t('Activity ID (aid)'),
    'help' => t('Activity ID'),
    'field' => array(
      'handler' => 'views_handler_field',
      'click sortable' => TRUE
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric'
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric'
    ),
    'sort' => array(
      'handler' => 'views_handler_sort'
    )
  );
  $data['activity_teamie']['template'] = array(
      'real field' => 'template',
      'title' => 'Activity',
      'help' => 'Text describing the activity',
      'field' => array(
        'handler' => 'activity_teamie_handler_field_activity_text',
      ),

  );
  $data['activity_teamie']['data'] = array(
    'title' => 'Data',
    'help' => 'Data array',
    'field' => array(
      'handler' => 'views_handler_field',
    ),
  );
  $data['activity_teamie']['created'] = array(
    'title' => t('Created'),
    'help' => t('Created timestamp'),
    'sort' => array(
      'handler' => 'views_handler_sort_date'
    )
  );
  $data['activity_teamie']['updated'] = array(
    'title' => t('Updated'),
    'help' => t('Updated timestamp'),
    'field' => array(
      'handler' => 'views_handler_field_date',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort_date'
    )
  );

  /* ACTIVITY MAP */
  $data['activity_teamie_map']['table']['group'] = t('Activity');

  // Join with the {activity} table
  $data['activity_teamie']['table']['join'] = array(
    'activity_teamie_map' => array(
      'left_field' => 'aid',
      'field' => 'aid'
    )
  );
  $data['activity_teamie_map']['aid'] = array(
      'title' => t('Aid Map'),
      'help' => t('Aid Map'),
    'field' => array(
          'handler' => 'views_handler_field',
  ),
      'filter' => array(
        'handler' => 'views_handler_filter_numeric'
  ),
      'argument' => array(
        'handler' => 'views_handler_argument_numeric'
  )
  );
  $data['activity_teamie']['entity_type'] = array(
    'title' => t('Entity type'),
    'help' => t('Entity type of the associated entity'),
  'field' => array(
        'handler' => 'views_handler_field',
  ),
    'filter' => array(
      'handler' => 'views_handler_filter_string'
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_string'
    )
  );
  $data['activity_teamie']['entity_id'] = array(
    'title' => t('Entity ID'),
    'help' => t('Entity ID of the associated entity'),
  'field' => array(
        'handler' => 'views_handler_field',
  ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric'
    )
  );
  return $data;
}
  • Did you try defining the join in the base table? – Jedihe Oct 21 '11 at 23:06
  • Yes. and edited my question with latest code. can you please help – Srihitha Narra Oct 24 '11 at 3:44
  • 1
    Since I don't have enough time to try it, the best I can offer is point you to drupal.stackexchange.com/questions/3275/… . Those steps allow you to create a views integration for an arbitrary schema, and then you can dump the code and check it against yours to find the problem. – Jedihe Oct 31 '11 at 3:20
4
$data['activity_teamie']['table']['join'] = array(
  'activity_teamie_map' => array(
    'left_field' => 'aid',
    'field' => 'aid'
  )
);

You actually want to join the other way round.kk

A general tip, try to think of some kind of similar join relation in Drupal core and look it up in views/modules/$module.views.inc

$data['activity_teamie']['entity_id'] = array(

Isn't entity_id part of activity_teamie_map?

| improve this answer | |

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.