From 704fbf7e0352787a6d42d39cb1e1fb44465ac770 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cam=20Sa=C3=BCl?= <cammsaul@gmail.com>
Date: Wed, 31 Aug 2016 12:19:03 -0700
Subject: [PATCH] Make sure field-ids is non-empty / fix API 500 :wrench:

---
 src/metabase/api/table.clj | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/metabase/api/table.clj b/src/metabase/api/table.clj
index ac0faa305b3..56795215a27 100644
--- a/src/metabase/api/table.clj
+++ b/src/metabase/api/table.clj
@@ -84,13 +84,14 @@
   (let-404 [table (Table id)]
     (read-check table)
     (let [field-ids (db/select-ids Field, :table_id id, :visibility_type [:not= "retired"])]
-      (for [origin-field (db/select Field, :fk_target_field_id [:in field-ids])]
-        ;; it's silly to be hydrating some of these tables/dbs
-        {:relationship   :Mt1
-         :origin_id      (:id origin-field)
-         :origin         (hydrate origin-field [:table :db])
-         :destination_id (:fk_target_field_id origin-field)
-         :destination    (hydrate (Field (:fk_target_field_id origin-field)) :table)}))))
+      (when (seq field-ids)
+        (for [origin-field (db/select Field, :fk_target_field_id [:in field-ids])]
+          ;; it's silly to be hydrating some of these tables/dbs
+          {:relationship   :Mt1
+           :origin_id      (:id origin-field)
+           :origin         (hydrate origin-field [:table :db])
+           :destination_id (:fk_target_field_id origin-field)
+           :destination    (hydrate (Field (:fk_target_field_id origin-field)) :table)})))))
 
 (defendpoint POST "/:id/sync"
   "Re-sync the metadata for this `Table`."
-- 
GitLab