Fork me on GitHub
#datomic
<
2016-02-18
>
casperc08:02:59

When i want to replace an entity with a new version of the same entity, but still be able to see the old version of the entity in the history, how do I go about doing this?

casperc08:02:26

And by replace i mean that: cardinality many entities should be replaced (not added to), and values not present in the new version not be present after the replace.

casperc08:02:31

I was thinking to retractEntity before asserting the new in the same transaction, but I am getting a :db.error/datoms-conflict Two datoms in the same transaction conflict

casperc09:02:51

I guess I could write a transaction function that finds out which fields to add and which fields to retract. Just seems like an obvious use case that might already be present.

robert-stuttaford09:02:02

or you could do two transactions - db.fn/retractEntity followed by asserting all the new facts

meow10:02:46

Can multiple transactions take place in the same "commit"?

robert-stuttaford10:02:08

you can put lots of data into a single transaction, but you can’t make multiple conflicting alterations to a single entity in one go

robert-stuttaford10:02:36

e.g. assert a two new values for a cardinality/one attr

casperc12:02:51

=> (instance? (d/entity (d/db @mem-conn) [:bygning/id 12345]) datomic.query.EntityMap)
ClassCastException   [trace missing]
=> (instance? (d/entity (d/db @mem-conn) [:bygning/id 12345]) datomic.Entity)
ClassCastException   [trace missing]

casperc12:02:11

How do I test if what I have in hand is an Entity map?

dm312:02:51

you have your arguments in the wrong order

casperc13:02:01

ah doh, you are right.