Fork me on GitHub

Can Crux model one-to-many relationships in the reverse direction as Datomic can? For example, if a parent can have many children, how would a child find its parent?


hi @US05F3A2E πŸ™‚ yes - what do your documents look like? i.e. is it the child that's responsible for keeping a reference to the parent, or a parent to its children? (if you haven't already chosen, I'd probably go with the child keeping a reference to its parent)


Actually, I was thinking more in terms of many to many relationships. For example, if A points to x and y, and B points to y and z, how does y determine what points to it?


in that case, 'y' could be modelled as a document in its own right (useful if you want to store further details about y), or it could be an element in a vector stored in both A and B


when you have a vector as a value in a Crux document, we index each element separately - e.g.

(crux/submit-tx node [[:crux.tx/put {:crux.db/id :parent-doc-1
                                     :myapp/children [:child-1 :child-2]}]
                      [:crux.tx/put {:crux.db/id :parent-doc-2
                                     :myapp/children [:child-2 :child-3]}]])
(crux/q (crux/db node) '{:find [parent]
                         :where [[parent :myapp/children :child-2]]})
returns #{[:parent-doc-1] [:parent-doc-2]}


That's pretty cool. The domain I'm working on has a lot of many to many relationships between many different types of entities. I'm thinking of using namespaced UUIDs for IDs to make it easier to see what types the relationships refer to, eg, [:entityA/uuid1 :entityB/uuid2 ...]. Does that cause any problem for indexing?


shouldn't do - in fact, we'd recommend it πŸ™‚


Is there a recommended way of implementing a unique constraint, say on a person's email address?


Hi @US05F3A2E there was a recent thread about this exact thing:;cid=CG3AM2F7V ...I'll update the FAQ tonight πŸ˜€


Thanks for that! In my case, the unique value will usually be a composite of two or more attributes, one of which is usually a string. As there's the option of changing that string, I guess I'd then have to create a new unique document corresponding to the new string, and then delete the original document?


Yep that sounds about right. Using a map as an ID might help you there too:


Congrats on 20.02-1.7.0-alpha!

πŸ‘ 4

Looking at cruxdockerhub, there isn’t anything there:


hey @dotemacs, thanks πŸ™‚ those are getting built as we speak, expect them under and shortly

πŸŽ‰ 12
πŸ‘ 8