I need retrive data from a custom table in drupal db by a colum that match with a drupal field in a content type.

I have this table:

The id_equipage is a varchar and is unique.
records example:
cliowave123abs|ABS of my Renault Clio|150|1
cliowave123oth|Some other option of my Renault Clio|10|1
cliowave123air|Air cond of my Renault Clio|250|1
meganeliveabs|ABS of my Renault Megane|310|1

Now I have a content type called car whit a text field equipages (table field_data_equipages) with unlimited values.

In this field I add all the id_equipage of the car.
So for example I have a node (nid: 5) like this:
Title: Clio Wave 2013
1. cliowave123abs
2. cliowave123air

Now, When I read the node (nid: 5), I want retrive the 2 records from my custom table
cliowave123abs|ABS of my Renault Clio|150|1
cliowave123air|Air cond of my Renault Clio|250|1

Can I do this whit the hook_views_data()??

Can you help me?!


  • This seems like pretty standard fare to me? Which part do you have problems with? Describing the table itself or describing the join?
    – user49
    Jul 19, 2014 at 19:20
  • The join. If I add a view of content i cant add the column of my custom table because doesn't exist relationship.
    – Fra Ore
    Jul 19, 2014 at 19:23
  • I need something like this SELECT c.* FROM field_data_field_equipages a JOIN node b ON a.entity_id = b.nid AND a.entity_type = 'node' JOIN equipages c ON a.field_equipages_value = c.id_equipage WHERE nid = 9
    – Fra Ore
    Jul 19, 2014 at 19:23

1 Answer 1


I believe this https://www.drupal.org/node/810932#comment-3020000 comment describes exactly what you need which is the extra field in a join description:

$data['node']['table']['join'] = array(
  // this explains how the 'node' table (named in the line above)
  // links toward the node_revision table.
  'node_revision' => array(
    'left_field' => 'nid',
    'field' => 'nid',
    'extra' => array(array('field' => 'fieldname', 'value' => 'value', 'operator' => '='))


  • Thanks... The problem is that in my custom table (equipages) I have not nid column. My foreign key is the id_equipage that has to join with the table field_data_field_equipages.
    – Fra Ore
    Jul 20, 2014 at 8:56
  • just add 'field'.
    – user49
    Jul 20, 2014 at 11:43

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.