Fork me on GitHub

Hi friends. I'm reading the Datomic docs on tuple bindings for multiple inputs ( in order to ask the 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]
       [?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]]
     ["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


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


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


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


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


thanks val_waeselynck


@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


hm good point


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