How to relate nodes by field, not title? I'm using Feeds to import content from XML. The content is films and their showtimes, like this:

&lt;film id=av1&gt;
  &lt;title&gt;Avatar&lt;/title&gt;
  &lt;showtimes total="2"&gt;
    &lt;showtime show_id="1" id="av1" date="1/1/2012" price="10" /&gt;
    &lt;showtime show_id="2" id="av1" date="2/1/2012" price="15" /&gt;
  &lt;showtimes&gt;
&lt;film&gt;


Right now, I've created two content types (Film and Showtime) and using Node Reference (References module) to relate Showtime to Film. Then I have various views that use the relationship to show listings, date listings etc.

This works ok, but Node Reference can only link on node title, so if someone updates the film title in the source feed we get problems. It would be better to link using the ID field, which never changes.

The problem is that I'm using Feeds to import to two content types, so running two Feeds importers, and they have to use title from the source to sync. So say the Film title is changed in Drupal, then more Showtimes get added to the XML. On import, the new Showtime nodes are created but can't find their Film node. Using the ID field from the source would keep things joined up. Maybe using Field Collection instead of referenced content types is better?

Possible solutions:


Use a taxonomy vocabulary and create a new term 'id' for each film. Then tag showtimes with the same term. I'm not sure this is a good use of taxonomy, creating single-connections in this way?
See if Relation module provides linking by field. Probably won't work with Feeds yet.
Create a single content type for films, and use Field Collection to store the showtimes. Then everything is connected in a single node. Not sure how feasible this is.


Any guidance or suggestions welcomed!
You are mistaken. Node reference uses the node id - the primary key for nodes to create the reference. The form element where you need to enter the node you want to reference, uses autocomplete to make it easier to find the node you want to reference, but the value stored is the node id. So there is actually no problem in using node reference and changing the title.

Code from the node reference module to illustrate this, can be found where the schema is defined for the field type it uses to create these reference:

/**
 * Implements hook_field_schema().
 */
function node_reference_field_schema($field) {
  $columns = array(
    'nid' =&gt; array(
      'type'     =&gt; 'int',
      'unsigned' =&gt; TRUE,
      'not null' =&gt; FALSE,
    ),
  );
  return array(
    'columns' =&gt; $columns,
    'indexes' =&gt; array('nid' =&gt; array('nid')),
    'foreign keys' =&gt; array(
      'nid' =&gt; array(
        'table' =&gt; 'node',
        'columns' =&gt; array('nid' =&gt; 'nid'),
      ),
    ),
  );
}