This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-05-12
Channels
- # admin-announcements (1)
- # aleph (1)
- # arachne (10)
- # beginners (6)
- # boot (81)
- # braveandtrue (3)
- # cider (42)
- # cljs-dev (1)
- # cljs-edn (52)
- # cljsjs (9)
- # cljsrn (9)
- # clojure (62)
- # clojure-austin (1)
- # clojure-belgium (11)
- # clojure-berlin (2)
- # clojure-gamedev (2)
- # clojure-greece (1)
- # clojure-russia (73)
- # clojure-uk (98)
- # clojurescript (156)
- # community-development (4)
- # component (3)
- # cursive (30)
- # datascript (10)
- # datomic (17)
- # emacs (5)
- # events (1)
- # hoplon (315)
- # jobs (1)
- # jobs-discuss (3)
- # lein-figwheel (6)
- # luminus (18)
- # off-topic (13)
- # om (130)
- # other-languages (122)
- # re-frame (32)
- # reagent (27)
- # rethinkdb (6)
- # ring (2)
- # ring-swagger (31)
- # spacemacs (4)
- # untangled (6)
- # yada (30)
Hi friends. I'm reading the Datomic docs on tuple bindings for multiple inputs (http://docs.datomic.com/query.html#sec-5-7-1) in order to ask the http://learndatalogtoday.org dataset, "What movies did both Mel Gibson and Danny Glover collaborate on?" And here's what works for me (apologies for using DataScript syntax, since that's what I'm using):
(d/q '[:find ?movie-title
:in $ [?name-1 ?name-2]
:where
[?person-1 :person/name ?name-1]
[?person-2 :person/name ?name-2]
[?movie :movie/cast ?person-1]
[?movie :movie/cast ?person-2]
[?movie :movie/title ?movie-title]]
@conn
["Danny Glover" "Mel Gibson"])
My question is, if I wanted to generalize this function to handle N>=2 collaborators, would I basically build that :where
clause programmatically to include N sub-vectors of [?person-n :person/name ?name-n]
and N other vectors of [?movie :movie/cast ?person-n]
, for n
running from 1 to N?
I.e., is there another, less intricate, way to enforce AND requirements other than this? Of course using collection bindings, with :in $ [?name ...]
will give me movies where any of the N actors have appeared, with an OR relationship, rather than AND (collaborations), which is what I need.
I suspect it would be advantageous for me to read up on Datomic rules at this juncture
@fasiha: good question, worth asking on stackoverflow or the mailing list
@fasiha: not sure if it's less intricate, but I think I'm able to do in one query it using 2 datasources and double-negation
is there a good guide you guys can recommend to learn about data modeling in datomic? I’m hoping to learn about modeling one to many relationships, and just relationships between entities in general
am i correct in my reading of the pull
API documentation that it doesn't specify any ordering?
@bvulpes: I don't believe you can really on any-order in Datomic queries
@adamkowalski: @bvulpes technically I'd say that a cardinality many ref attribute is always many to many - IMO the best way to enforce one-to-many from A to B is a to-one ref attribute from B to A; keep in mind that such attribute cannot be a component then
@adamkowalski: have you read the best practices? http://docs.datomic.com/best-practices.html
And finally, some other personal data modeling tips: - don't hesitate to reflect on how generic your attributes can be. Sharing attributes across different entity types can be very powerful. - for "joint table"-like entities you may need compound identifiers, see this discussion https://groups.google.com/forum/#!topic/datomic/4cjJxiH9Lkw
@bvulpes: @val_waeselynck Thanks for all the tips! I have not read those yet, so I will definitely look at those before I continue in my project.