Fork me on GitHub
#fulcro
<
2023-10-10
>
Jakub Holý (HolyJak)22:10:40

@tony.kay is there a way to get :db/id of an entity from the auto-generated datomic resolvers in fulcro-rad-datomic? It seems that com.fulcrologic.rad.database-adapters.datomic-common/fix-id-keys makes it go away 🥲 Context: I need to sort entities by creation date but do not have any attribute tracking it, and pull doesn’t make it possible to get the transaction timestamp. But I have been told that the value of db/id contains a time component, that I could extract and use for this purpose. I just need to figure out how to get it out of the resolvers… fix-id-keys (result = {:db/id 79164837200017, :order-line/id #uuid "018a1478-8d0f-8781-a404-059c1cd9cbd8", ...} => {nil 79164837200017, :order-line/id #uuid "018a1478-8d0f-8781-a404-059c1cd9cbd8", ...} - so db/id becomes nil, I believe due to this line https://github.com/fulcrologic/fulcro-rad-datomic/blob/main/src/main/com/fulcrologic/rad/database_adapters/datomic_common.clj#L109 (since id-key in this context is nil, b/c for some reason it isn’t included in the query [and even if it was, db/id wouldn’t be preserved]). Any tips? 🙏

tony.kay23:10:22

I think you’re looking at native ID support, where you don’t use UUIDs. So, you can mark attributes as identity and native. The native will use :db/id and rename it (as that line is doing), but only if it is marked as native. If it isn’t marked as native, then you could just add a :long attribute to your RAD model named :db/id and set it’s ao/identities to all of the id attributes that you want it to be supported by

tony.kay00:10:15

The :db/id renaming shouldn’t happen if native isn’t marked, but there could be a bug for that since no one has ever tried it.

tony.kay00:10:19

Yeah, that line of code you’re pointing to should ONLY rename it if it is marked as native. That’s a bug

Jakub Holý (HolyJak)07:10:59

> If it isn’t marked as native, then you could just add a :long attribute to your RAD model named :db/id and set it’s ao/identities to all of the id attributes that you want it to be supported by Yes, that is what I tried to do, and I guess the :ladybug: got in the way.