Fork me on GitHub
Aleksander Rendtslev02:03:48

Is it possible to add data to an edge/relation? I know that I could annotate the type of relation by designating it in the property of the document doing the reference eg:

:person/friends [:johnny]
But this starts to become impractical when the type of relation isn’t known up front. Eg a generic post or entry that maps relationships to entities of different contexts. Is it possible to add meta data?
:entry/refs [{:edge "eats" :ref :pizza} {:edge "friend" :ref :johnny} {:edge "reading" :ref :lord-of-the-ringns]

;;as opposed to
:entry/eats [:pizza]
:entry/reads [:lord-of-the-rings]
:entry/friends [:johnny]
The latter is impractical from an application point of you. Or maybe I’m just thinking about this wrong? I believe you can do this in datomic with tuples, but I haven’t worked with it


One thing you can do is add an entity with an ID that corresponds to the edge, such as with map IDs, like :crux.db/id {:e :some-e :a :entry/refs :v :pizza} you can then add the edge data to that document. Constructing the maps in Datalog isn't pleasant but works. Alternatively you could consider pulling the edges out to be first-class entities with UUID IDs, with a pair of directed references like :from :some-e :to :pizza