Skip to main content
edited tags
Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284
Source Link

Drupal 7 Views with custom tables Join

I have a custom table clinic_consultation and using the field doctor_id which is the uid from the Users table, I couldn't join the tables together to come with a name field of the Users table in the same view

here is what I did, but I can not find any solution for joining both tables to display the name field from the users table

 $data['clinic_consultations']['table']['group'] = t('clinic_consultations table');

  $data['clinic_consultations']['table']['base'] = array(
    'field' => 'consultation_id',
    'title' => t('Consultation table'), 
    'help' => t('Consultation table contains all listed Consultations'), 
    'weight' => -10,
  );

  $data['clinic_consultations']['consultation_id'] = array(
   'title' => t('Cons ID'), 
    'help' => t('Cons ID'),
   'relationship' => array(
      'base' => 'node',
      'field' => 'consultation_id',
     'handler' => 'views_handler_relationship', 
     'label' => t('Cons ID'),
   ),
);

$data['clinic_consultations']['consultation_id'] = array(
    'title' => t('Cons ID'), 
    'help' => t('Cons ID.'), 
    'field' => array(
      'handler' => 'views_handler_field', 
      'click sortable' => TRUE,
    ), 
    'sort' => array(
      'handler' => 'views_handler_sort',
    ), 
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ), 
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
    ),
  );


  $data['clinic_consultations']['consultation_date'] = array(
    'title' => t('Cons Date'), 
    'help' => t('Cons Date'), 
    'field' => array(
      'handler' => 'views_handler_field', 
      'click sortable' => TRUE,
    ), 
    'sort' => array(
      'handler' => 'views_handler_sort',
    ), 
    'filter' => array(
      'handler' => 'views_handler_filter_date',
    ), 
    'argument' => array(
      'handler' => 'views_handler_argument_date',
    ),
  );

   $data['clinic_consultations']['patient_id'] = array(
    'title' => t('PTN ID'), 
    'help' => t('PTN ID'), 
    'field' => array(
      'handler' => 'views_handler_field', 
      'click sortable' => TRUE,
    ), 
    'sort' => array(
      'handler' => 'views_handler_sort',
    ), 
    'filter' => array(
      'handler' => 'views_handler_filter_string',
    ), 
    'argument' => array(
      'handler' => 'views_handler_argument_string',
    ),
  );

    $data['clinic_consultations']['doctor_id'] = array(
    'title' => t('Doctor ID'), 
    'help' => t('Doctor ID'), 
    'field' => array(
      'handler' => 'views_handler_field', 
      'click sortable' => TRUE,
    ), 
    'sort' => array(
      'handler' => 'views_handler_sort',
    ), 
    'filter' => array(
      'handler' => 'views_handler_filter_string',
    ), 
    'argument' => array(
      'handler' => 'views_handler_argument_string',
    ),
  );

     $data['clinic_consultations']['consultation_type'] = array(
    'title' => t('Consultation Type'), 
    'help' => t('Consultation Type'), 
    'field' => array(
      'handler' => 'views_handler_field', 
      'click sortable' => TRUE,
    ), 
    'sort' => array(
      'handler' => 'views_handler_sort',
    ), 
    'filter' => array(
      'handler' => 'views_handler_filter_string',
    ), 
    'argument' => array(
      'handler' => 'views_handler_argument_string',
    ),
  );


    $data['clinic_consultations']['table']['join'] = array(
          'avatar' => array(
            'left_table' => 'users',
            'left_field' => 'uid',
            'field' => 'name',
            'table' => 'clinic_consultations',

        ),
      );