This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-03-25
Channels
- # babashka (77)
- # beginners (107)
- # calva (20)
- # cider (2)
- # clj-kondo (7)
- # clojure (63)
- # clojure-australia (2)
- # clojure-europe (75)
- # clojure-germany (10)
- # clojure-italy (3)
- # clojure-nl (3)
- # clojure-serbia (15)
- # clojure-spain (2)
- # clojure-uk (24)
- # clojurescript (54)
- # clojureverse-ops (3)
- # cursive (20)
- # datahike (4)
- # datalog (5)
- # datascript (8)
- # datomic (13)
- # emacs (2)
- # fulcro (1)
- # graalvm (2)
- # instaparse (1)
- # jobs (2)
- # luminus (1)
- # malli (7)
- # off-topic (28)
- # pathom (6)
- # pedestal (2)
- # re-frame (5)
- # reagent (9)
- # remote-jobs (4)
- # rewrite-clj (4)
- # ring (19)
- # shadow-cljs (2)
- # spacemacs (2)
- # sql (10)
- # tools-deps (6)
- # xtdb (12)
Hopefully this is the right place to ask this... I'm struggling with constraining a join across a one-to-many association:
(d/q '[:find (pull ?p [:post/slug
{:post/fields
[:field/key
:field/lang
:field/content]}])
:in $ ?slug ?lang
:where
[?p :post/slug ?slug]
[?p :post/fields ?field]
[?field :field/lang ?lang]]
db "child-page" :en)
This returns fields in all languages, not just :en
, which is not what I want. I suspect this is because :post/fields
is :db.cardinality/many
and the join does not constrain them properly. Is this possible or do I need to filter fields after the fact?You can perform a query + pull in that find clause. Try this:
(d/q '[:find ?slug (pull ?field
[:field/key
:field/lang
:field/content])
:in $ ?slug ?lang
:where
[?p :post/slug ?slug]
[?p :post/fields ?field]
[?field :field/lang ?lang]]
db "child-page" :en)
If you really want a map you could do:
(d/q '[:find ?slug ?key ?lang ?content
:in $ ?slug ?lang
:keys post/slug field/key field/lang field/content
:where
[?p :post/slug ?slug]
[?p :post/fields ?field]
[?field :field/key ?key]
[?field :field/lang ?lang]
[?field :field/content ?content]
db "child-page" :en)