Index: modules/taxonomy/taxonomy.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.install,v
retrieving revision 1.20
diff -u -p -r1.20 taxonomy.install
--- modules/taxonomy/taxonomy.install	18 Jun 2009 15:46:30 -0000	1.20
+++ modules/taxonomy/taxonomy.install	2 Aug 2009 21:26:21 -0000
@@ -140,43 +140,6 @@ function taxonomy_schema() {
     ),
     'primary key' => array('tid', 'vid'),
   );
-
-  $schema['taxonomy_term_relation'] = array(
-    'description' => 'Stores non-hierarchical relationships between terms.',
-    'fields' => array(
-      'trid' => array(
-        'type' => 'serial',
-        'not null' => TRUE,
-        'description' => 'Primary Key: Unique term relation ID.',
-      ),
-      'tid1' => array(
-        'type' => 'int',
-        'unsigned' => TRUE,
-        'not null' => TRUE,
-        'default' => 0,
-        'description' => 'The {taxonomy_term_data}.tid of the first term in a relationship.',
-      ),
-      'tid2' => array(
-        'type' => 'int',
-        'unsigned' => TRUE,
-        'not null' => TRUE,
-        'default' => 0,
-        'description' => 'The {taxonomy_term_data}.tid of the second term in a relationship.',
-      ),
-    ),
-    'unique keys' => array(
-      'tid1_tid2' => array('tid1', 'tid2'),
-    ),
-    'indexes' => array(
-      'tid2' => array('tid2'),
-    ),
-    'foreign keys' => array(
-      'tid1' => array('taxonomy_term_data' => 'tid'),
-      'tid2' => array('taxonomy_term_data' => 'tid'),
-    ),
-    'primary key' => array('trid'),
-  );
-
   $schema['taxonomy_term_synonym'] = array(
     'description' => 'Stores term synonyms.',
     'fields' => array(
@@ -362,3 +325,51 @@ function taxonomy_update_7002() {
   }
   return $ret;
 }
+
+/**
+ * Create a term field for 'related terms'.
+ */
+function taxonomy_update_7009() {
+  $ret = array();
+  // Confirm whether any related terms exist in the database.
+  if (db_query('SELECT COUNT(*) FROM {taxonomy_term_relation}')->fetchField()) {
+    // Create a 'related_terms' field.
+    $field = array(
+      'field_name' => 'related_terms',
+      'type' => 'taxonomy_term',
+    );
+    field_create_field($field);
+
+    // Drupal 6 allows related terms for all vocabularies whether or not
+    // explicitly set, so ignore the 'relations' column in
+    // {taxonomy_vocabulary} and create field instances for each vocabulary.
+    $instance = array(
+      'field_name' => 'related_terms',
+      'label' => 'Related terms',
+    );
+    foreach (taxonomy_get_vocabularies() as $vocabulary) {
+      $instance['bundle'] = $vocabulary->machine_name;
+      $instance['settings']['allowed_values']['vid'] = $vocabulary->vid;
+      field_create_instance($instance);
+    }
+
+    // Fetch all
+    $result = db_query('SELECT tid1, tid2 FROM {taxonomy_term_relation} ORDER BY trid ASC');
+    foreach ($result as $record) {
+      $relations[$record->tid1][] = $record->tid2;
+    }
+
+    // Load all terms which have relations, populate the field information,
+    // then save it.
+    $terms = taxonomy_term_load_multiple(array_keys($relations));
+    foreach ($terms as $tid => $term) {
+      foreach ($relations[$tid] as $delta => $relation) {
+        $term->related_terms[$delta]['value'] = $relation;
+      }
+      taxonomy_term_save($term);
+    }
+  }
+  db_drop_table($ret, 'taxonomy_term_relation');
+  db_drop_field($ret, 'taxonomy_vocabulary', 'relations');
+
+}
Index: modules/taxonomy/taxonomy.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.module,v
retrieving revision 1.492
diff -u -p -r1.492 taxonomy.module
--- modules/taxonomy/taxonomy.module	2 Aug 2009 15:44:08 -0000	1.492
+++ modules/taxonomy/taxonomy.module	2 Aug 2009 21:26:23 -0000
@@ -436,25 +436,6 @@ function taxonomy_term_save($term) {
     module_invoke_all('taxonomy_term_insert', $term);
   }
 
-  db_delete('taxonomy_term_relation')
-    ->condition(db_or()
-      ->condition('tid1', $term->tid)
-      ->condition('tid2', $term->tid)
-    )
-    ->execute();
-
-  if (!empty($term->relations)) {
-    foreach ($term->relations as $related_id) {
-      if ($related_id != 0) {
-        db_insert('taxonomy_term_relation')
-          ->fields(array(
-            'tid1' => $term->tid,
-            'tid2' => $related_id
-          ))
-          ->execute();
-      }
-    }
-  }
   db_delete('taxonomy_term_hierarchy')
     ->condition('tid', $term->tid)
     ->execute();
@@ -545,12 +526,6 @@ function taxonomy_term_delete($tid) {
       db_delete('taxonomy_term_hierarchy')
         ->condition('tid', $tid)
         ->execute();
-      db_delete('taxonomy_term_relation')
-        ->condition(db_or()
-          ->condition('tid1', $tid)
-          ->condition('tid2', $tid)
-        )
-        ->execute();
       db_delete('taxonomy_term_synonym')
         ->condition('tid', $tid)
         ->execute();
@@ -974,23 +949,6 @@ function taxonomy_node_type($op, $info) 
 }
 
 /**
- * Find all term objects related to a given term ID.
- */
-function taxonomy_get_related($tid, $key = 'tid') {
-  if ($tid) {
-    $result = db_query('SELECT t.*, tid1, tid2 FROM {taxonomy_term_relation}, {taxonomy_term_data} t WHERE (t.tid = tid1 OR t.tid = tid2) AND (tid1 = :tid1 OR tid2 = :tid2) AND t.tid != :tid ORDER BY weight, name', array(':tid' => $tid, ':tid1' => $tid, ':tid2' => $tid));
-    $related = array();
-    foreach ($result as $term) {
-      $related[$term->$key] = $term;
-    }
-    return $related;
-  }
-  else {
-    return array();
-  }
-}
-
-/**
  * Find all parents of a given term ID.
  */
 function taxonomy_get_parents($tid, $key = 'tid') {
Index: modules/taxonomy/taxonomy.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.test,v
retrieving revision 1.41
diff -u -p -r1.41 taxonomy.test
--- modules/taxonomy/taxonomy.test	31 Jul 2009 07:43:33 -0000	1.41
+++ modules/taxonomy/taxonomy.test	2 Aug 2009 21:26:23 -0000
@@ -395,30 +395,6 @@ class TaxonomyTermTestCase extends Taxon
   }
 
   /**
-   * Test related terms.
-   */
-  function testTaxonomyTermRelations() {
-    // Create two taxonomy terms.
-    $term1 = $this->createTerm($this->vocabulary);
-    $term2 = $this->createTerm($this->vocabulary);
-
-    // Edit $term1 and add $term2 as a relationship.
-    $edit = array();
-    $edit['relations[]'] = $term2->tid;
-    $this->drupalPost('taxonomy/term/' . $term1->tid . '/edit', $edit, t('Save'));
-    $related = taxonomy_get_related($term1->tid);
-    $this->assertTrue(isset($related[$term2->tid]), t('Related term was found'));
-    // Create a third term.
-    $term3 = $this->createTerm($this->vocabulary);
-    $edit['relations[]'] = $term3->tid;
-    $this->drupalPost('taxonomy/term/' . $term1->tid . '/edit', $edit, t('Save'));
-
-    $related = taxonomy_get_related($term1->tid);
-    $this->assertTrue(isset($related[$term3->tid]), t('Related term was found'));
-    $this->assertFalse(isset($related[$term2->tid]), t('Term relationship no longer exists'));
-  }
-
-  /**
    * Test synonyms.
    */
   function testTaxonomySynonyms() {
