Fork me on GitHub
#datomic
<
2016-05-12
>
fasiha05:05:21

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"])

fasiha05:05:55

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?

fasiha05:05:05

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.

fasiha05:05:39

I suspect it would be advantageous for me to read up on Datomic rules at this juncture

val_waeselynck08:05:03

@fasiha: good question, worth asking on stackoverflow or the mailing list

val_waeselynck08:05:12

@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

adamkowalski18:05:32

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

bvulpes18:05:13

adamkowalski one-to-many is a cardinality many 'ref'

bvulpes21:05:54

am i correct in my reading of the pull API documentation that it doesn't specify any ordering?

bvulpes21:05:45

it appears to be ordered by transaction, but confirmation would be nice

val_waeselynck21:05:58

@bvulpes: I don't believe you can really on any-order in Datomic queries

bvulpes21:05:34

thanks val_waeselynck

val_waeselynck22:05:27

@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

bvulpes22:05:33

hm good point

val_waeselynck22:05:06

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

adamkowalski22:05:40

@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.