Fork me on GitHub
#xtdb
<
2020-02-27
>
vsined08:02:35

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?

jarohen09:02:54

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)

vsined09:02:48

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?

jarohen10:02:02

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

jarohen10:02:50

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]}

vsined16:02:58

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?

jarohen16:02:56

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

vsined16:02:46

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

refset17:02:16

Hi @US05F3A2E there was a recent thread about this exact thing: https://clojurians.slack.com/archives/CG3AM2F7V/p1581442893076700?thread_ts=1581442893.076700&amp;cid=CG3AM2F7V ...I'll update the FAQ tonight ๐Ÿ˜€

vsined04:02:35

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?

refset12:02:29

Yep that sounds about right. Using a map as an ID might help you there too: https://github.com/juxt/crux/commit/dd03a3613f9a076116d87ca0500f2350302ecec8

dotemacs16:02:44

Congrats on 20.02-1.7.0-alpha!

๐Ÿ‘ 4
dotemacs16:02:45

Looking at cruxdockerhub, there isnโ€™t anything there: https://hub.docker.com/u/cruxdockerhub

jarohen16:02:33

hey @dotemacs, thanks ๐Ÿ™‚ those are getting built as we speak, expect them under https://github.com/juxt/crux/releases and https://hub.docker.com/u/juxt shortly

๐ŸŽ‰ 12
๐Ÿ‘ 8