Currently TW can only relate base tables to base tables using views relationships.

It would be very useful to be able to relate any TW table to a TW base table by creating classic views join definitions. For instance, see how term_data, term_node relate to node:

  $data['vocabulary']['table']['join'] = array(
    // vocabulary links to term_data directly via vid.
    'term_data' => array(
      'left_field' => 'vid',
      'field' => 'vid',
    ),
    // vocabulary links to node through term_data via vid
    'node' => array(
      'left_table' => 'term_data',
      'left_field' => 'vid',
      'field' => 'vid',
    ),
    // vocabulary links to node_revision via term_data
    'node_revision' => array(
      'left_table' => 'term_data',
      'left_field' => 'vid',
      'field' => 'vid',
    ),
  );

Comments

mikeryan’s picture

Category: bug » feature
alex_b’s picture

Status: Active » Needs review
StatusFileSize
new3.28 KB

This patch provides join information for tables that have been related through the tw UI but the right table is not a base table. Before this gets committed, we should at least adjust the UI. Another nice to have feature would be allowing for joins across more than one table.

I'm posting this here to get a first review and see whether such a patch would be welcome.

alex_b’s picture

StatusFileSize
new5.54 KB

This iteration adjusts the UI. It replaces the usage of "Relationship" in favor of "Relate tables" and explains that TW creates a views relationship if the right table is a base table and join information if the right table is not a base table.

alex_b’s picture

StatusFileSize
new10.61 KB

Once we have related non-base tables to base tables we can generate default views for these non-base tables. This iteration does that (see changes to tw.views_default.inc.

For now, simple non-base to base joins work. I haven't tested with joins over more than two tables yet. Mike: Let me know if you like where this is going.

mikeryan’s picture

Sorry, haven't had time to fully consider this... Right now I want to prioritize getting a stable 1.0 release out, then look at this for 2.0.

Thanks.

mikeryan’s picture

I haven't had time to try out your patch. Just some thoughts on the general principle, with an eye towards implementing it in the next release of the Table Wizard:

My first instinct when implementing relationships is that I much prefer Views relationships to Views joins, in that building a view then doesn't clutter things up with all available related fields by default. I.e., let the user creating the view decide whether they want to deal with the additional fields. However, default joins do make a lot of sense for fields which are basically integer enums with names/descriptions in a related tables (like the role table) - you're generally going to want to display that name in the view, not the ID.

So, I think relationships need to have a flag whether to use a join or a relationship (in Views terminology). Relationship would be the default, but when the relationship is not available (one or both tables not a base table), only the join would be available.

Thoughts?

frankcarey’s picture

I think I like having this automated as much as possible (not having to add relationships), but maybe we can build the logic to so that if a table can't become a base table (used in relationships), it gets added through joins instead. Are there any performance considerations in doing it one way or another? Like if the view doesn't need a field from a joined table it won't join it, right? You can filter fields by groups as well, so that makes finding fields easier.

I just had to implement this manually to get {node} to join to {term_node}. I think whatever we do, we should also provide a way for integration modules to override the $tables object, which i did by adding a hook. I'll bring this up in a new issue.

mikeryan’s picture

Assigned: Unassigned » mikeryan
Status: Needs review » Needs work

OK, I've committed support for specifying each relationship as Automatic (i.e., using a Views join) or Manual (using a Views relationship). It basically works, but is under-tested. Be sure to run update.php before trying it.

Thanks.

mikeryan’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.