Fork me on GitHub
#datomic
<
2024-02-15
>
jaret13:02:24

Thanks Ivar! I will address

🧡 1
cch122:02:35

I've been exploring entity specs for my application and I was surprised to see the "virtual" :db/ensure attribute appear when pulling "spec'd" entities. This is so counter-intuitive I wonder if I'm doing something wrong.

cch122:02:11

The docs (https://docs.datomic.com/cloud/schema/schema-reference.html#entity-specs) clearly state that: • :db/ensure is a virtual attribute • it is not added to the database But after transacting the initial assertions of my domain entity with :db/ensure, I subsequently see a ref attribute on the entity:

(d/pull db '[*] 101155069759907)
=>
{:db/id 101155069759907,
 :db/ensure [#:db{:id 87960930222306, :ident :st.data-source/valid?}],
 :st.data-source/id #uuid "0dcff1a1-3785-45c2-846f-de72401ba810",
 :st.data-source/credentials #:db{:id 101155069759908},
 :st.data-source/type :st.data-source.type/tesla}

cch122:02:47

The referenced entity is in fact the entity I had previously transacted into my schema to support the "named" ensure:

{:db/ident        :st.data-source/valid?
  :db.entity/attrs [:st.data-source/id :st.data-source/type]}

cch122:02:44

Perhaps relevant: this is using dev-local.

favila22:02:00

I’ve seen it in datomic-pro also

cch123:02:08

First: thanks for the confirmation. I thought I was going crazy. Second, any idea of a work-around?

favila23:02:22

workaround?

cch123:02:48

It seems like Datomic is not recognizing the :db/ensure attribute as "special" and is instead creating a reference with that name.

favila23:02:06

are you seeing it not perform the ensure?

cch123:02:29

I'm not sure TBH -I had not gotten that far.

cch123:02:47

I just assumed I was doing something wrong. That's next on my list of exploring.

favila23:02:52

ok, my experience is it definitely does whatever assertions it’s supposed to do, it just happens to be written into the db

cch123:02:20

If it's written, that begs the question: is the opt-in permanent since the attr is permanent?

cch123:02:50

So I still need to assert it on subsequent txs... good to know.

favila23:02:08

The only oddity is that the :db/add is eventually materialized as a datom instead of being stripped, and that’s only odd because they said it wouldn’t be

favila23:02:22

you should still treat it like a “verb” instead of data

✔️ 1
cch123:02:05

As usual, your knowledge and helpfulness are unparalled!

Joe Lane23:02:11

This is something we were coincidentally looking into this week already. Invariants are definitely enforced, just leaves some noise that nobody intended.

cch100:02:52

Good to know. And with that confidence, I'll happily move along!