"y :attr x" or "x :attr y"

#1

I’ve designed my entity so that it has a many-ref relationship field, so Bob would have “employs Frank”, “eats-at Joe’s”, “bowls-with Jeff”, and since these are all under Bob, I made a query so that Joe could ask “Who eats at my place?”

[:find [?client ...] :in $ ?provider
:where [?rel-id :relationship/party ?provider]
[?client :user/relationships ?rel-id]]

which, great. But I also want to be able to ask “Who has any relationship to Bob?”

Bob [whatever] who?
who? [whatever] Bob

Not an “and” but an “or”.

0 Likes

#2

Not sure but you may need to enumerate the relationships you want to check in an or-join

0 Likes

#3

This works:

[:find 
 (pull ?e [*])
 :where 
 
 ; :community/name starts-with? "A", or
 ; :neighborhood/name starts-with? "A"
 
 [(ground #{:community/name
            :neighborhood/name}) [?a ...]]
 [?e ?a ?name]
 [(clojure.string/starts-with? ?name "A")]]

http://demo.hyperfiddle.net/:dustingetz!datomic-query-any-attr/

0 Likes