Index: relativity.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/relativity/relativity.module,v
retrieving revision 1.49
diff -u -p -r1.49 relativity.module
--- relativity.module	12 Jan 2008 02:27:19 -0000	1.49
+++ relativity.module	8 Jul 2009 10:16:48 -0000
@@ -39,6 +39,23 @@ function relativity_node_list($use_blank
 }
 
 /**
+ * Lists the children of a given parent node.
+ *
+ * @param int $parent_nid The node id of the node for which you want the children
+ * @return array of child node objects
+ */ 
+function relativity_list_children($parent_nid) {
+  $child_nodes = array();
+  
+  $result = db_query('SELECT nid FROM {relativity} WHERE parent_nid = %d', $parent_nid);
+  while ($child = db_fetch_object($result)) {
+    $child_nodes[] = node_load($child->nid);
+  }
+  
+  return $child_nodes;
+}
+
+/**
  * Lists nodes that could be attached to a given parent type.
  *
  * TODO:
@@ -1471,11 +1488,8 @@ function theme_relativity_show_children(
   $output = '';
 	
   // load all nodes associated with this one as the parent nid and show links to all of them.
-  $result = db_query('SELECT nid FROM {relativity} WHERE parent_nid = %d', $parent->nid);
-  while($child = db_fetch_object($result)) {
-    $child_nodes[] = node_load($child->nid);
-  }
-  if (!is_array($child_nodes)) return '';
+  $child_nodes = relativity_list_children($parent->nid);
+  if (!is_array($child_nodes) || count($child_nodes) == 0) return '';
 
   $childrentypes = relativity_childrentypes($parent); // sorted list of types
 
@@ -1581,13 +1595,11 @@ function theme_relativity_show_link_oper
   if ($output) {
     $output = "\n" . '<div class="relativity_add_child">' . $output . "</div>\n";
   }
+  $output = ($output ? $output . '<br />' : '');
 
   // show child removal links
-  $result = db_query('SELECT nid FROM {relativity} WHERE parent_nid = %d', $parent_nid);
-  $output = ($output ? $output . '<br />' : '');
-  while($child = db_fetch_object($result)) {
-    $child_node = node_load($child->nid);
-    // make sure that no dependencies exist that would require this node to be attached
+  $child_nodes = relativity_list_children($parent_nid);
+  foreach($child_nodes as $child_node) {
     if (relativity_may_unchild($parent, $child_node)) {
       $removables[] = $child_node;
     }
