Skip to content
Snippets Groups Projects
Commit cbd5e688 authored by Allen Gilliland's avatar Allen Gilliland
Browse files

add 'target' to Field returned by 'sel' post-select macro. 'target' refers to...

add 'target' to Field returned by 'sel' post-select macro.  'target' refers to the Field an 'fk' type points to.
parent c93e5e7f
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,8 @@
(:require [korma.core :refer :all]
[metabase.api.common :refer [check]]
[metabase.db :refer :all]
(metabase.models [database :refer [Database]])
(metabase.models [database :refer [Database]]
[foreign-key :refer [ForeignKey]])
[metabase.util :as util]))
(def special-types
......@@ -73,10 +74,13 @@
(defentity Field
(table :metabase_field))
(defmethod post-select Field [_ {:keys [table_id] :as field}]
(defmethod post-select Field [_ {:keys [id special_type table_id] :as field}]
(util/assoc* field
:table (delay (sel :one 'metabase.models.table/Table :id table_id))
:db (delay @(:db @(:table <>)))
:target (delay (when (= "fk" special_type)
(let [dest-id (:destination_id (sel :one :fields [ForeignKey :destination_id] :origin_id id))]
(sel :one Field :id dest-id))))
:can_read (delay @(:can_read @(:table <>)))
:can_write (delay @(:can_write @(:table <>)))))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment