create relation between two nodes using the relation module
I have a module that uses Hierarchical Select to give users a nice looking UI to create relations from.

Below is an excerpt of how I create the relation.

  $tid = 1; // A term id.
  $node = node_load(1);
  $relation_bundle = 'a_type_of_relation';

  $endpoints = array();
  $endpoints[] = array('entity_type' =&gt; 'taxonomy_term', 'entity_id' =&gt; $tid);
  $endpoints[] = array('entity_type' =&gt; 'node', 'entity_id' =&gt; $node-&gt;nid);

  $new_relation = relation_create($relation_bundle, $endpoints);

  if ($rid = relation_save($new_relation)) {
    drupal_set_message(t('Relation created'), 'status', FALSE);
  }
  else {
    drupal_set_message(t('Creating relation failed'), 'warning', FALSE);
  }


Adding more useful validation and messages is left as an exercise to reader, as that will be very context sensitive.