Cannot join two fields from my table to one base table

Events happening in the community are now at Drupal community events on www.drupal.org.
diricia's picture

I've created a module with a table that has the following fields

+------------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+------------------+------+-----+---------+-------+
| type | varchar(128) | NO | PRI | | |
| tid_group | int(10) unsigned | NO | PRI | 0 | |
| tid | int(10) unsigned | NO | PRI | 0 | |
| node_count | int(10) unsigned | NO | | 0 | |
+------------+------------------+------+-----+---------+-------+

Fields tid_group and tid are taxonomy tid's. To expose these fields I want them both to link to the tid field in term_data.

From the syntax that I've looked at this will cause one array element for the first field, only to be overridden by the second. See below. It seems I have to use the exact keys for both fields.

  $data['taxonomy_hash_count']['table']['join']['term_data'] = array(
        'left_field' => 'tid',
      'field' => 'tid_group'
  );
$data['taxonomy_hash_count']['table']['join']['term_data'] = array(
        'left_field' => 'tid',
      'field' => 'tid'
    );

How will I be able to do this? Is it perhaps possible to create two ..views.inc files that exposes each seperately?

Any input would be much appreciated. I've created this module so that the number of terms grouped by another category can be saved in nodeapi as there will be millions of records. This will be much more efficient, doing queries from the database will kill the server.

In my case I want to know how many nodes have a certain classification (e.g household, office) per region/province.

Comments

Two fields to one base table

cvdenzen's picture

This is certainly possible. I have seen examples of this, you will have to use aliases. See http://views-help.doc.logrus.com/help/views/api-tables.
This is what should do the trick:

$data['taxonomy_hash_count_A']['table']['join']['term_data'] = array(
        'table' => 'taxonomy_hash_count', # the name of the real table, taxonomy_hash_count_A is the alias
        'left_field' => 'tid',
        'field' => 'tid_group'
  );
$data['taxonomy_hash_count_B']['table']['join']['term_data'] = array(
        'table' => 'taxonomy_hash_count',
        'left_field' => 'tid',
       'field' => 'tid',
  );

Thank you

diricia's picture

Thank you so much for your help.
I'll definitely use it to improve my module which I will then release to drupal.org

Views Developers

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week