datomic

enn 2026-03-19T22:58:55.855629Z

What is the most idiomatic way to write a query that joins two entities and returns them in one "bucket"? For example, let's say I want to return all nodes in a tree that match some criterion, and their parents:

[:find [?node ...]
 :in $ ?type
 :where
  [?node :node/type ?type]
  [?node :node/parent ?parent]]
I want to return the union of matching ?node and ?parent values, ideally in a single collection. Can I do this with a subquery? With or ?

cch1 2026-03-20T16:43:37.909109Z

I've used rules with multiple inputs for this. Easy-peasy.

2026-03-19T23:06:33.024479Z

i believe this is a pull

2026-03-19T23:06:41.589649Z

i'm on my phone or i'd pull up the docs for you

enn 2026-03-19T23:08:57.926029Z

I want a set of entity ids, not maps. I don't think you can do this with pull.

👍 1
enn 2026-03-19T23:11:36.840079Z

(of course I could get the maps and pull out the entity IDs after ... but I'm wondering if there is some way to do this directly in the query.)

jumraiya 2026-03-19T23:11:44.321889Z

Maybe a recursive rule?

favila 2026-03-19T23:18:39.756599Z

Or

favila 2026-03-19T23:18:59.010999Z

(Or rule with multiple impls)

braai engineer 2026-03-29T21:53:50.812399Z

@enn d/index-range against heterogeneous tuple :node/type+parent – essentially an index on type + parent. Are you only looking for immediate descendants of that specific parent, or a recursive tree? d/pull can do recursive queries as Noah said.