Allow for multiple distinct links between the same two entities.

This commit is contained in:
Simon Brooke 2018-07-07 09:06:13 +01:00
parent 66d4b2af4d
commit 7d62976880
4 changed files with 37 additions and 26 deletions

View file

@ -306,7 +306,7 @@
"\n\tAND " entity-name "." link-field " = :id")
(order-by-clause entity "lv_"))
"link" (let [link-table-name
(link-table-name entity far-entity)]
(link-table-name % entity far-entity)]
(list
(str "-- :name " query-name " " signature)
(str "-- :doc links all existing " pretty-name " records related to a given " pretty-far)

View file

@ -37,6 +37,12 @@
;;; to-hugsql-queries, because essentially we need one JSON entry point to wrap
;;; each query.
;;; TODO: memoisation of handlers probably doesn't make sense, because every request
;;; will be different. I don't think we can memoise HugSQL, at least not without
;;; hacking the library (might be worth doing that and contributing a patch).
;;; So the solution may be to an intervening namespace 'cache', which has one
;;; memoised function for each hugsql query.
(defn file-header [application]
(list
'ns
@ -65,21 +71,25 @@
(defn generate-handler-body
"Generate and return the function body for the handler for this `query`."
[query]
(list
[{:keys ['params 'form-params]}]
(list 'let
(vector
'result
(list
(let [action (list
(symbol (str "db/" (:name query)))
'db/*db*
(list 'support/massage-params
'params 'form-params (key-names (:entity query)))))
'params
'form-params
(key-names (:entity query))))]
(list
[{:keys ['params 'form-params]}]
(case
(:type query)
(:delete-1 :update-1)
'(response/found "/")
(list 'response/ok 'result)))))
(list
action
'(response/found "/"))
(list
'let
(vector 'result action)
(list 'response/ok 'result))))))
(defn generate-handler-src

View file

@ -461,7 +461,7 @@
#(and
(entity? %)
(= (:name (:attrs %)) (:entity (:attrs property)))))
link-table-name (link-table-name e1 e2)]
link-table-name (link-table-name property e1 e2)]
(if
;; we haven't already emitted this one...
(not (@emitted-link-tables link-table-name))

View file

@ -146,6 +146,7 @@
([field-or-property form entity application]
(prompt field-or-property))
([field-or-property]
(capitalise
(or
(first
(children
@ -154,7 +155,7 @@
(= (:tag %) :prompt)
(= (:locale :attrs %) *locale*))))
(:name (:attrs field-or-property))
(:property (:attrs field-or-property)))))
(:property (:attrs field-or-property))))))
(defn csrf-widget