diff --git a/includes/fields.inc b/includes/fields.inc
index 9b08f38..80a1c74 100644
--- a/includes/fields.inc
+++ b/includes/fields.inc
@@ -306,3 +306,37 @@ function ctools_fields_get_fields_by_type($field_type) {
   }
   return $fields;
 }
+
+/**
+ * Derive the foreign keys that a field provides.
+ *
+ * @param $field_name
+ *   The name of the field.
+ *
+ * @return
+ *   An array of foreign keys according to Schema API.
+ */
+function ctools_field_foreign_keys($field_name) {
+  $foreign_keys = &drupal_static(__FUNCTION__, array());
+  if (!isset($foreign_keys[$field_name])) {
+    $foreign_keys[$field_name] = array();
+    $field = field_info_field($field_name);
+
+    if (!empty($field['foreign keys'])) {
+      $foreign_keys[$field_name] = $field['foreign keys'];
+    }
+    else {
+      // try to fetch foreign keys from schema, as not everything
+      // stores foreign keys properly in the field info.
+      $module = $field['module'];
+
+      module_load_install($module);
+      $schema = module_invoke($module, 'field_schema', $field);
+      if (!empty($schema['foreign keys'])) {
+        $foreign_keys[$field_name] = $schema['foreign keys'];
+      }
+    }
+  }
+
+  return $foreign_keys[$field_name];
+}
diff --git a/plugins/relationships/entity_from_field.inc b/plugins/relationships/entity_from_field.inc
index 8d2f2db..0d6ea72 100644
--- a/plugins/relationships/entity_from_field.inc
+++ b/plugins/relationships/entity_from_field.inc
@@ -45,95 +45,80 @@ function ctools_entity_from_field_get_children($parent_plugin, $parent) {
       // field instance is still shown.
       if (!empty($entities[$from_entity]['bundles'][$bundle])) {
         foreach ($fields as $field_name => $field) {
-          $field = field_info_field($field_name);
-          $foreign_keys = NULL;
+          $foreign_keys = ctools_field_foreign_keys($field_name);
+
+          foreach ($foreign_keys as $key => $info) {
+            if (isset($info['table'])) {
+              foreach ($entities as $to_entity => $to_entity_info) {
+                $from_entity_info = $entities[$from_entity];
+                // If somehow the bundle doesn't exist on the to-entity,
+                // skip.
+                if (!isset($from_entity_info['bundles'][$bundle])) {
+                  continue;
+                }
 
-          if (!empty($field['foreign keys'])) {
-            $foreign_keys = $field['foreign keys'];
-          }
-          else {
-            // try to fetch foreign keys from schema, as not everything
-            // stores foreign keys properly in the field info.
-            $module = $field['module'];
-            module_load_install($module);
-            $schema = module_invoke($module, 'field_schema', $field);
-            if (!empty($schema['foreign keys'])) {
-              $foreign_keys = $schema['foreign keys'];
-            }
-          }
+                if (isset($to_entity_info['base table']) && $to_entity_info['base table'] == $info['table'] && array_keys($info['columns'], $to_entity_info['entity keys']['id'])) {
+                  $name = $field_name . '-' . $from_entity . '-' . $to_entity;
+                  $plugin_id = $parent . ':' . $name;
+
+                  // Record the bundle for later.
+                  $context_types[$plugin_id]['types'][$bundle] = $from_entity_info['bundles'][$bundle]['label'];
+
+                  // We check for every bundle; this plugin may already have
+                  // been created, so don't recreate it.
+                  if (!isset($plugins[$plugin_id])) {
+                    $plugin = $parent_plugin;
+                    $replacements = array(
+                      '@to_entity' => $to_entity_info['label'],
+                      '@from_entity' => $from_entity_info['label'],
+                      '@field_name' => $field_name,
+                      '@field_label' => ctools_field_label($field_name),
+                    );
+                    $plugin['title'] = t('@to_entity from @from_entity (on @from_entity: @field_label [@field_name])', $replacements);
+                    $plugin['keyword'] = $to_entity;
+                    $plugin['context name'] = $name;
+                    $plugin['name'] = $plugin_id;
+                    $plugin['description'] = t('Creates a @to_entity context from @from_entity using the @field_name field on @from_entity.', $replacements);
+                    $plugin['from entity'] = $from_entity;
+                    $plugin['to entity'] = $to_entity;
+                    $plugin['field name'] = $field_name;
+                    $plugin['join key'] = $key;
+                    $plugin['source key'] = current(array_keys($info['columns']));
+                    $plugin['parent'] = $parent;
+
+                    $plugins[$plugin_id] = $plugin;
 
-          if (is_array($foreign_keys)) {
-            foreach ($foreign_keys as $key => $info) {
-              if (isset($info['table'])) {
-                foreach ($entities as $to_entity => $to_entity_info) {
-                  $from_entity_info = $entities[$from_entity];
-                  // If somehow the bundle doesn't exist on the to-entity,
-                  // skip.
-                  if (!isset($from_entity_info['bundles'][$bundle])) {
-                    continue;
-                  }
-
-                  if (isset($to_entity_info['base table']) && $to_entity_info['base table'] == $info['table'] && isset($info['columns'][$to_entity_info['entity keys']['id']])) {
-                    $name = $field_name . '-' . $from_entity . '-' . $to_entity;
+/*
+-- commented out until I figure out how to actually load the reverse properly.
+                    // Build the reverse
+                    $plugin = $parent_plugin;
+                    $name = $field_name . '-' . $from_entity . '-' . $to_entity . '-reverse';
                     $plugin_id = $parent . ':' . $name;
 
-                    // Record the bundle for later.
-                    $context_types[$plugin_id]['types'][$bundle] = $from_entity_info['bundles'][$bundle]['label'];
-
-                    // We check for every bundle; this plugin may already have
-                    // been created, so don't recreate it.
-                    if (!isset($plugins[$plugin_id])) {
-                      $plugin = $parent_plugin;
-                      $replacements = array(
-                        '@to_entity' => $to_entity_info['label'],
-                        '@from_entity' => $from_entity_info['label'],
-                        '@field_name' => $field_name,
-                        '@field_label' => ctools_field_label($field_name),
-                      );
-                      $plugin['title'] = t('@to_entity from @from_entity (on @from_entity: @field_label [@field_name])', $replacements);
-                      $plugin['keyword'] = $to_entity;
-                      $plugin['context name'] = $name;
-                      $plugin['name'] = $plugin_id;
-                      $plugin['description'] = t('Creates a @to_entity context from @from_entity using the @field_name field on @from_entity.', $replacements);
-                      $plugin['from entity'] = $from_entity;
-                      $plugin['to entity'] = $to_entity;
-                      $plugin['field name'] = $field_name;
-                      $plugin['parent'] = $parent;
-
-                      $plugins[$plugin_id] = $plugin;
-
-/*
- -- commented out until I figure out how to actually load the reverse properly.
-                      // Build the reverse
-                      $plugin = $parent_plugin;
-                      $name = $field_name . '-' . $from_entity . '-' . $to_entity . '-reverse';
-                      $plugin_id = $parent . ':' . $name;
-
-                      $plugin['title'] = t('@from_entity from @to_entity (on @from_entity: @field_name)', $replacements);
-                      $plugin['keyword'] = $to_entity;
-                      $plugin['context name'] = $name;
-                      $plugin['name'] = $plugin_id;
-                      $plugin['description'] = t('Creates a @from_entity context from @to_entity using the @field_name field on @from_entity.', $replacements);
-
-                      $plugin['from entity'] = $from_entity;
-                      $plugin['to entity'] = $to_entity;
-                      $plugin['field name'] = $field_name;
-                      $plugin['reverse'] = TRUE;
-                      $plugin['parent'] = $parent;
-
-                      // Since we can't apply restrictions on the reverse relationship
-                      // we just add the required context here.
-                      $plugin['required context'] = new ctools_context_required($to_entity_info['label'], $to_entity);
-
-                      $plugin_entities = array(
-                        'to' => array($from_entity => $from_entity_info),
-                        'from' => array($to_entity => $to_entity_info)
-                      );
-                      drupal_alter('ctools_entity_context', $plugin, $plugin_entities, $plugin_id);
-
-                      $plugins[$plugin_id] = $plugin;
+                    $plugin['title'] = t('@from_entity from @to_entity (on @from_entity: @field_name)', $replacements);
+                    $plugin['keyword'] = $to_entity;
+                    $plugin['context name'] = $name;
+                    $plugin['name'] = $plugin_id;
+                    $plugin['description'] = t('Creates a @from_entity context from @to_entity using the @field_name field on @from_entity.', $replacements);
+
+                    $plugin['from entity'] = $from_entity;
+                    $plugin['to entity'] = $to_entity;
+                    $plugin['field name'] = $field_name;
+                    $plugin['reverse'] = TRUE;
+                    $plugin['parent'] = $parent;
+
+                    // Since we can't apply restrictions on the reverse relationship
+                    // we just add the required context here.
+                    $plugin['required context'] = new ctools_context_required($to_entity_info['label'], $to_entity);
+
+                    $plugin_entities = array(
+                      'to' => array($from_entity => $from_entity_info),
+                      'from' => array($to_entity => $to_entity_info)
+                    );
+                    drupal_alter('ctools_entity_context', $plugin, $plugin_entities, $plugin_id);
+
+                    $plugins[$plugin_id] = $plugin;
 */
-                    }
                   }
                 }
               }
@@ -172,11 +157,11 @@ function ctools_entity_from_field_context($context, $conf) {
   $delta = !empty($conf['delta']) ? intval($conf['delta']) : 0;
   $plugin = $conf['name'];
   list($plugin, $plugin_name) = explode(':', $plugin);
-  list($field_name, $from_entity, $to_entity_info) = explode('-', $plugin_name);
+  list($field_name, $from_entity, $to_entity) = explode('-', $plugin_name);
   // If unset it wants a generic, unfilled context, which is just NULL.
   $entity_info = entity_get_info($from_entity);
   if (empty($context->data) || !isset($context->data->{$entity_info['entity keys']['id']})) {
-    return ctools_context_create_empty('entity:' . $to_entity_info, NULL);
+    return ctools_context_create_empty('entity:' . $to_entity, NULL);
   }
 
   if (isset($context->data->{$entity_info['entity keys']['id']})) {
@@ -185,16 +170,18 @@ function ctools_entity_from_field_context($context, $conf) {
     $entity = entity_load($from_entity, array($id));
     $entity = $entity[$id];
     if ($items = field_get_items($from_entity, $entity, $field_name)) {
-      $to_entity_info_info = entity_get_info($to_entity_info);
       if (isset($items[$delta])) {
-        $to_entity_info_id = $items[$delta][$to_entity_info_info['entity keys']['id']];
+        ctools_include('fields');
+        $to_entity_info = entity_get_info($to_entity);
+        $plugin_info = ctools_get_relationship($conf['name']);
+        $to_entity_id = $items[$delta][$plugin_info['source key']];
 
         // Send it to ctools.
-        return ctools_context_create('entity:' . $to_entity_info, $to_entity_info_id);
+        return ctools_context_create('entity:' . $to_entity, $to_entity_id);
       }
       else {
         // In case that delta was empty.
-        return ctools_context_create_empty('entity:' . $to_entity_info, NULL);
+        return ctools_context_create_empty('entity:' . $to_entity, NULL);
       }
     }
   }
