While working on a project to join an entity table to a data table on one of the entity field values, I came across this comment at http://cgit.drupalcode.org/data/tree/data.views.inc?h=7.x-1.x#n58 :

        // @todo: See if left table has other tables it is linked to and link
        // all the way to the leftmost table.

@alex_b - any leads on how to do that? I'd take a stab at it!

Comments

bc’s picture

Issue tags: -#views #relationships #entity reference
bc’s picture

Related: rejected support request #897814 and https://drupal.org/node/898496 as well

bc’s picture

As a stopgap solution, I am using hook_views_data_alter to add a join to any view that includes a certain field: https://github.com/ESDet/esdportal_str/blob/7.x-1.x/esdportal_str.module...

This could be generalized in data.views.inc somehow...

joachim’s picture

    if (isset($view['table']['join']['field_data_field_bcode'])) {
      $field = $view['table']['join']['field_data_field_bcode']['field'];
      $view['table']['join']['taxonomy_term_data'] = array(
        'left_table' => 'field_data_field_bcode',
        'left_field' => 'field_bcode_value',
        'field' => $field,
      );

Why not just use a taxonomy term reference field?

bc’s picture

Joachim, do you mean I should add an entity reference to the data table?

In my case, data tables are non-modifiable. Also, based on alex_b's comment it looks like there are other cases where this functionality comes into play.

joachim’s picture

> Joachim, do you mean I should add an entity reference to the data table?

I don't mean a new database field to your data table, but a FieldAPI field. It looks like you've already done that -- is field_data_field_bcode not a FieldAPI table? If it's storing taxonomy term IDs, then you are better off using a proper refererence field.

bc’s picture

field_data_field_bcode is a FieldAPI field used by a taxonomy term entity type, hence the two joins.

Data table has a column "bcode", which can be joined with the FieldAPI field_data_field_bcode table's field_bcode_value column, which can then be joined via field_data_field_bcode.entity_id to a taxonomy term

joachim’s picture

Ah, I get it.
You're much better off using an entityreference field, either from your Data entity to the taxonomy terms, or the other way round. You'll get the relationships in both directions in both cases.