Fork me on GitHub

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 ?


@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:


@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...


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


@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 :)


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


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


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


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


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


@bhagany yeah it is upsert.


@bhagany and it is ondatomic free. H2.


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


@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.


@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


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