Do you even need the lookup ref there?
@sfyire you don’t need the lookup ref, as zane said. Internally, lookup refs are resolved to the :db/id
of the specific entity, so what you have written is “redundant”. If charlie-id
is indeed a :db/id
, then you can transact the link directly:
(datahike/transact
connection
{:tx-data [{:db/id bob-id, :best-friend charlie-id}]})
With ref-type attributes, the v
in the [e a v]
tuple is the e
of the entity to reference. So in your example the tuple would be [bob-id :best-friend charlie-id]
.
In fact, I don’t believe [:db/id 123]
is even a valid lookup ref (as you’ve discovered), because :db/id
is a built-in attribute; it’s not a ref-type attribute defined in your schema.Thank you for the information, what's the significance of :tx-data? I'm not at my laptop but I thought I could do non ref based updates without the :tx-data key I just assumed I could update anything with that "syntax"
@sfyire you’re correct in that you can process transactions without using the :tx-data
key, and can pass the sequence directly. I believe that it’s there in order to be compatible with Datomic (where its use is mandated). Datahike is based on the Datascript project, where the syntax is a bit “looser”.
Datomic supports an additional :timeout
key as well, so the map form is more open in the options it can accept.
@cjsauer oh I see so I would need to add :tx-data
all the time in updates for Datomic? But Datascript and thus Datahike will accept without a :tx-data
in some circumstances?
@sfyire right. If compatibility with Datomic is important, for example if you foresee one day migrating, then it might be better to use the more portable map form. This is my impression anyway. Others here might have more insight.