Reputation: 35762
My question is - is there a way to join two entities in Dataomic, that don't have a reference in the schema, without resorting to writing two nested iterators (a manual join).
In the Datomic Doco - they give an example of a query specifying two parameters.
[:find ?n ?u
:where
[?c :community/name ?n]
[?c :community/url ?u]]
They call this a 'join' - because the underlying structure is a key-value database - so even attributes of the same entity need to be 'joined' together.
Then they give an example of a join between two entities that have a reference (assume the reference is defined in the schema which is not shown here):
[:find ?c_name
:where
[?c :community/name ?c_name]
[?c :community/neighborhood ?n]
[?n :neighborhood/district ?d]
[?d :district/region :region/ne]]
My question is - is a query like the above possible without a reference in the schema? Or would I have to resort to writing an iterator and trawling through the results?
Upvotes: 4
Views: 891
Reputation: 1038
Any variable that occurs more than once in the :where clause is implictly joined over.
So you can ask for names that belong to a community as well as to a neighbourhoord
(def results (q '[:find ?name :where [_ :neighborhood/name ?name]
[_ :district/name ?name]]
(db conn)))
Is this what you were asking for? (ids are just ignored in this example)
Upvotes: 3