Datomic many to many with data on the relationship

蹲街弑〆低调 提交于 2021-01-29 13:59:20

问题


I'd like to implement a many to many relationship which also has metadata describing the relationship. One could think of the relationship as a labelled edge. Specifically, a path consists of an ordered collection of series, and a series can be within more than one path, on each occasion having a position within such path. If I understand correctly some reification of the relationship is needed in datomic (as we cannot label edges directly), such as a join entity like:

:path/path-member      ; ref, many

:path-member/series    ; ref, one
:path-member/position  ; long, one

Or to reify it more completely:

:path-member/series    ; ref, one
:path-member/path      ; ref, one
:path-member/position  ; long, one

Are there any other data modelling options that could work?

Are composite attributes relevant here?

This question has been asked before but I wondered if any additions to datomic since that question was asked (2015) offer any new possibilities.


回答1:


Almost everyone encounters this question when they start data modelling with datomic, as evidenced by the large number of stack overflow questions on exactly the same point.

There is great news: Heterogenous tuples, added in June 2019, are a powerful new feature which solves this beautifully - it's exactly the feature we all thought was missing.

What it means is an attribute value, i.e. the v in the eavto 5-tuple, can now itself be a tuple.

This is a clojure vector of max length 8. While this length limitation does not go the full way to allowing an arbitrary amount of meta-data to be stored as labels on an edge, as in a true graph db, it adds great modelling power to datomic while retaining all the rest of the leverage and simplicity datomic provides.

Official blog post announcement.

Discussion of the release on twitter.

To use this in datalog, all you need are the tuple and untuple functions. It's beautifully simple, and is exactly the feature that was 'missing'.



来源:https://stackoverflow.com/questions/61386621/datomic-many-to-many-with-data-on-the-relationship

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!