diff --git a/relation.install b/relation.install
index afeb2c9..79915c1 100644
--- a/relation.install
+++ b/relation.install
@@ -262,3 +262,25 @@ function relation_update_7001() {
     ->condition('field_name', 'endpoints')
     ->execute();
 }
+
+/**
+ * Update empty rid in relation_revision table
+ */
+function relation_update_7002() {
+  // Update statements with JOINs are not portable across SQL dialects.
+  // First get revisions needing update;
+  // retrieve all results before updating anything.
+  $query = db_select('relation_revision', 'v');
+  $query->join('relation', 'r', 'v.vid = r.vid');
+  $results = $query->fields('r', array('rid', 'vid'))
+    ->condition('v.rid', 0, '=')
+    ->execute()
+    ->fetchAll();
+  // Update all those revisions with the correct rid.
+  foreach ($results as $result) {
+    db_update('relation_revision')
+      ->fields(array('rid' => $result->rid))
+      ->condition('vid', $result->vid, '=')
+      ->execute();
+  }
+}
diff --git a/relation.module b/relation.module
index 795cc31..accaa6d 100644
--- a/relation.module
+++ b/relation.module
@@ -744,6 +744,10 @@ function relation_save($relation) {
   catch (FieldValidationException $e) {
     return FALSE;
   }
+  // Determine if we will be inserting a new relation.
+  if (!isset($relation->is_new)) {
+    $relation->is_new = empty($relation->rid);
+  }
   $transaction = db_transaction();
   $endpoints = field_get_items('relation', $relation, 'endpoints');
   $relation->arity = count($endpoints);
@@ -764,6 +768,12 @@ function relation_save($relation) {
   unset($relation->vid);
   drupal_write_record('relation_revision', $relation);
   drupal_write_record('relation', $relation, $keys);
+  if ($relation->is_new) {
+    db_update('relation_revision')
+      ->fields(array('rid' => $relation->rid))
+      ->condition('vid', $relation->vid)
+      ->execute();
+  }
   call_user_func("field_attach_$op", 'relation', $relation);
   module_invoke_all('entity_' . $op, $relation, 'relation');
   module_invoke('rules', 'invoke_event', 'relation_' . $op, $relation);
@@ -871,10 +881,10 @@ function relation_uri($relation) {
  * Returns a query object to find related entities.
  *
  * @param $entity_type
- *   The entity type of one of the endpoints.
+ *   (optional) The entity type of one of the endpoints.
  * @param $entity_id
- *   The entity id of one of the endpoints. Can also be an array of entity
- *   IDs.
+ *   (optional) The entity id of one of the endpoints. Can also be an array of 
+ *   entity IDs.
  * @param $r_index
  *   (optional) The index of the search entity in the relation to be found
  *   (0 = source, 1 = target).
