This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-30
Channels
- # bangalore-clj (1)
- # beginners (104)
- # boot (207)
- # cider (173)
- # cljs-dev (157)
- # cljsjs (1)
- # cljsrn (51)
- # clojure (196)
- # clojure-berlin (1)
- # clojure-chicago (1)
- # clojure-italy (4)
- # clojure-new-zealand (1)
- # clojure-nl (1)
- # clojure-russia (28)
- # clojure-spec (17)
- # clojure-uk (73)
- # clojured (13)
- # clojurescript (110)
- # core-async (4)
- # datascript (25)
- # datomic (92)
- # editors (1)
- # emacs (157)
- # events (4)
- # hoplon (16)
- # klipse (74)
- # lein-figwheel (10)
- # leiningen (2)
- # lumo (13)
- # off-topic (78)
- # om (3)
- # om-next (3)
- # onyx (14)
- # protorepl (1)
- # re-frame (17)
- # reagent (23)
- # remote-jobs (1)
- # ring-swagger (33)
- # schema (2)
- # slack-help (3)
- # spacemacs (7)
- # testing (1)
- # yada (7)
Alright. I need to make one query, then insert the id of that query as a reference, in a second query right after. What, exactly, do I need to grab from the return of d/transact!
that is used as a reference?
(my schema does indicate that in the second query, that field is {:db/type :db.type/ref}
)
Huh. is it really just {:db/id id}
? seems so.
is there any way to.... "resolve" this automatically when querying? like if I have a reference to another item, it could append the whole thing in the result?
aka if I do (seq (d/entity @conn [:message/id "275380583893434368"]))
I now get this
([:message/type 0]
[:message/timestamp "2017-01-29T21:44:07.524000+00:00"]
[:message/channel_id "274707618222833674"]
[:message/author {:db/id 3}]
[:message/id "275380583893434368"]
[:message/mention_everyone false]
[:message/tts false]
[:message/nonce "275380580646912000"]
[:message/pinned false]
[:message/content "with?"])
I'd like to get this instead
([:message/type 0]
[:message/timestamp "2017-01-29T21:44:07.524000+00:00"]
[:message/channel_id "274707618222833674"]
[:message/author ([:user/avatar "a_354e581b44cfc815036869f81c7810c6"]
[:user/discriminator "4611"]
[:user/id "139412744439988224"]
[:user/username "eslachance"])]
[:message/id "275380583893434368"]
[:message/mention_everyone false]
[:message/tts false]
[:message/nonce "275380580646912000"]
[:message/pinned false]
[:message/content "with?"])
(as an arbitrary "Expand all references, event nested ones" if possible)
@eslachance entities are lazy, no need to expand them
when printed, you don’t see that, but if you try to access (:user/id (:message/author (d/entity @conn [:message/id "275380583893434368"])))
you’ll get the id
so entities automatically follow references and any reference attribute is seen as another full entity
What if I need to simply output the whole thing?
if you need something like that, you can write your own function that walks all attributes and checks their types
Will do. What happens if there's a circular reference though... (yes this will most likely happen)
Alright. I'll need to figure out a way to do this then. I'll go from d/touch
and see what I can do. Thank you!
If all goes well within a few months I'll be making some nice tutorial videos for a few things I've learned... most likely Datascript will be part of that because, well, it's awesome 😄
I have an app using Datascript that works in dev mode but when I switch advanced compilation I’m getting errors from Datascript, like Lookup ref attribute should be marked as :db/unique: [:state/part :ui]
even though I have that attribute set as unique in my schema.
Is it common for users to run into issues like this with advanced compilation, or is that suprising?
it doesn’t look like simply switching to advanced compilation is the problem. I’ll keep looking