Allow for multiple distinct links between the same two entities

This commit is contained in:
Simon Brooke 2018-07-07 09:04:33 +01:00
parent a855554ed8
commit 9db4e48638

View file

@ -86,8 +86,11 @@
(defn link-table-name (defn link-table-name
"Canonical name of a link table between entity `e1` and entity `e2`." "Canonical name of a link table between entity `e1` and entity `e2`. However, there
[e1 e2] may be different links between the same two tables with different semantics; if
`property` is specified, and if more than one property in `e1` links to `e2`, generate
a more specific link name."
([e1 e2]
(s/join (s/join
"_" "_"
(cons (cons
@ -95,6 +98,18 @@
(sort (sort
(list (list
(:name (:attrs e1)) (:name (:attrs e2))))))) (:name (:attrs e1)) (:name (:attrs e2)))))))
([property e1 e2]
(if (count
(descendants
e1
#(and
(= (-> % :attrs :type) "link")
(=
(-> % :attrs :entity)
(-> property :attrs :entity)))))
(s/join
"_" (map #(:name (:attrs %)) (list property e1 e2)))
(link-table-name e1 e2))))
(defn children (defn children