Fork me on GitHub
#datomic
<
2018-08-03
>
rhansen14:08:18

Anyone else here have a problem when using cast/initialize-redirect :stdout in cider?

rhansen14:08:38

works when using the repl from CLI tools, fails within cider 😕

matthavener20:08:16

is it possible to create an entity in datomic with no attributes, only refs to it?

matthavener20:08:23

Eg I have two entities, 123 and 456, and a :db.cardinality/one :db.type/ref attribute. If I transact [[:db/add 123 :my/ref "foo"] [:db/add 456 :my/ref "foo"]] it fails

Joe Lane20:08:32

What would it be a ref to?

Joe Lane20:08:30

Aren’t you just saying entities 123 and 456 have the string "foo"?

Joe Lane20:08:59

At that point isn’t "foo" just a value instead of an entity?

matthavener20:08:06

It'd be a ref to an empty entity. I'm guessing the answer is just "you can't have an empty entity with only incoming references".

Joe Lane20:08:44

Yeah, I mean thats your answer, because it would be kind of like a null entity. I was more questioning what in your domain model would this empty ref represent and, if its a string like you proposed, should you think of "foo" as a static value instead of an entity. I reserve entities for things that change over time but still need a stable id of some sort.

marshall20:08:04

Entities are just a number. You can definitely have an "empty" entity with only 'incoming' refs

Joe Lane20:08:51

Sorry for adding confusion and misinformation then.

marshall20:08:53

Try your example using the map syntax

marshall20:08:34

{:db/id "foo"}
{:db/id 123
 :my/ref "foo"}
{:db/id 456
 :my/ref "foo"}

marshall20:08:01

You could also do list form. Add to your example above: [:db/add "foo" :db/id "foo"]

marshall20:08:19

I believe that last will work. I'm on my phone so I cant check it atm

marshall20:08:44

Note to self: figure out how to run a REPL on my phone :D

matthavener20:08:10

user=> (d/with db' [[:db/add 17592186046851 :my/ref "foo"] [:db/id 17592186046852 :my/ref "foo"] [:db/add "foo" :db/id "foo"]])

IllegalArgumentExceptionInfo :db.error/not-a-data-function Unable to resolve data function: :db/id  datomic.error/arg (error.clj:57)

matthavener20:08:27

trying map syntax

marshall21:08:06

You need a db/add in the middle list

matthavener21:08:45

user=> (d/with db' [[:db/add 17592186046851 :my/ref "foo"] [:db/add 17592186046852 :my/ref "foo"] [:db/add "foo" :db/id "foo"]])

IllegalArgumentExceptionInfo :db.error/not-an-entity Unable to resolve entity: :db/id  datomic.error/arg (error.clj:57)

matthavener21:08:07

user=> (d/with db' [{:db/id "foo"} {:db/id 17592186046851 :my/ref "foo"} {:db/id 17592186046852 :my/ref "foo"}])

IllegalArgumentExceptionInfo :db.error/tempid-not-an-entity tempid used only as value in transaction  datomic.error/arg (error.clj:57)

matthavener21:08:36

fwiw this is not a huge issue, we can add a token attribute onto "foo". I just thought it was weird 🙂

favila22:08:22

You can also try reversing the attribute. i.e. redesign the attribute so that the currently empty entity contains forward-ref to other things

favila22:08:37

there's no difference in size or speed between forward and reverse attrs

favila22:08:12

the only differences are ergonomic, * in pull expressions and d/touch won't look for them

favila22:08:57

(but my suggestion won't work if you're trying to enforce cardinality)

marshall21:08:59

It should work. I'll try to look into it this weekend

👍 4
marshall21:08:29

Cloud or onprem? And version?

matthavener21:08:46

om-prem, 0.9.5561

favila22:08:26

no this is correct, you can't use a tempid without using it as an :e in some assertion in the tx

favila22:08:02

consider reversing the attribute?

kenny22:08:04

Why does datomic.client.api/transact not throw an error when called like this?

(d/transact conn [{:db/id         bob-id
                   :user/name "bob"}])
This has bitten me so many times.

favila22:08:35

what is bob-id?

favila22:08:59

I'm guessing it resolves to some value that would be legal there?

kenny22:08:05

A :db/id. Doesn't matter for this. transact needs to provide feedback on the incorrect call.

favila22:08:13

what is incorrect?

kenny22:08:39

Should be:

(d/transact conn {:tx-data [{:db/id     bob-id
                             :user/name "bob"}]})

favila22:08:51

oh cloud api

kenny22:08:06

Yes. And I'm so used to the peer API I always forget to call it correctly.

favila22:08:09

forever confused that they use the same prefix by convention

favila22:08:22

yes that is terrible

favila22:08:27

it should error

favila22:08:48

map? predicate at least

favila22:08:19

if you give a non-sequential to the peer d/transact it errors

favila22:08:41

cloud should do likewise if it gets non-map

kenny22:08:59

I agree 100%. Right now the transaction succeeds, only transacting :db/txInstant.