Fork me on GitHub
#datomic
<
2015-09-27
>
voytech09:09:36

Hi. I would like to confirm something. If we have unique id e.g. username. Then me make a transaction to store userdetails. When we want to update user details it should be sufficient to make just similar transaction providing same username. Then tempid should be resolved to existing entity id ? And we thus we can change other properties ?

bhagany14:09:35

@voytech: In this case, you wouldn't use a temp id, you'd use a lookup ref. There's an example in this blog post: http://blog.datomic.com/2014/02/datomic-lookup-refs.html

voytech16:09:36

@bhagany Thanks for answer. I wil use lookup refs then, But i think documentation says that tempid should be resolved to existing id. It is in section about transactions I think. Or maybe I understand i wrong...

bhagany16:09:21

@voytech: It might, I'm not sure. But it's definitely easier to use the lookup ref.

voytech16:09:16

@bhagany At least lookup ref gives You control because by providing lookup ref You are explicitly defining transaction as an update. Hmm but when you are providing transaction with unique property :username which already exists in db - this should be update too - what else could happen ? Knowing that username already has this value we cannot create another entity with this value because it already exists. For me there are two results - failure or successfull update on existing entity :)

voytech16:09:46

@bhagany. My question was added here because after adding entity with the same username again I still have the old entity. This is strange...

bhagany16:09:10

@voytech: Hmm, that is odd… does your unique attribute have :db.unique/identity, or :db.unique/value?

voytech16:09:00

@bhagany. It is identity. Db.unique/identity.

bhagany16:09:06

@voytech: Okay. I found this thread, which seems related, but the bug they were talking about should be fixed: https://groups.google.com/forum/#!topic/datomic/30ADvlLV9f4

bhagany16:09:31

I would expect an upsert in the situation you're describing

voytech16:09:11

@bhagany yeah it is upsert.

voytech16:09:02

@bhagany and it is ondatomic free. H2.

bhagany16:09:04

@voytech: oh, I understood you to be saying that you ended up with two entities with the same unique attribute

voytech16:09:33

@bhagany no after upsert there is only old entity. I'll double check. Now i don't have access to my env. Maybe I'm doing something stupi somewhere around.

bhagany16:09:21

@voytech: okay, I see. In that case, I would double check to make sure you're using the db-after value from the transaction, instead of an old db

voytech17:09:31

@bhagany im getting new value using db func. But I need to ensure.