How to model entity type?

Is it a good pattern to have a “entity_type” attribute to help differentiate types of entities?

1 Like

I found a mention in faq: Modeling Types FAQs · XTDB Docs

1 Like

it is a known pattern. in general it would be advisable to call it :your.site/type or something else distinct

2 Likes

I use xtdb with Fulcro and tend to duplicate the :xt/id into :foo/id where foo is the type

3 Likes

I’m partial to using a map with a single key as :xt/id

So instead of having, {:xt/id #uuid "..."} you would have {:xt/id {:company/id #uuid "..."}}. That makes the types of entities very clear when navigating the database (for example in XTDB inspector).

It doesn’t help with queries like “list all companies”, but I usually handle those by using some required attribute that only that type of entity. (eg. where clause [?e :company/name])

2 Likes