Fork me on GitHub
#datomic
<
2015-10-28
>
wambat17:10:17

Hi all. I was trying to update value of isComponent ref with new set of data, is there a idiomatic way to do that? Updating ref with new values in map transaction just adding them to the set.

bhagany18:10:07

@wambat: I'm pretty sure you have to explicitly retract the elements in the old set, if you want to replace them.

wambat18:10:07

@bhagany: thanks, but that's sad to hear that.

Ben Kamphaus18:10:57

@wambat one strategy for this would be to define a cas-like transaction function that operates with logic: “if card/many attr on this entity still has the same set of values, retract that set and assert this new set"

Ben Kamphaus18:10:37

but yeah, cardinality one will handle retractions of old data w/assertions of new but card many will add new assertions unless you supply retractions.

wambat18:10:21

I'll try adding the function, thanks @bkamphaus .

domkm21:10:59

@bkamphaus: I think I figured out a solution that avoids the complications and any potential problems I might have had with 'with'. Thanks for your help. :)

Ben Kamphaus21:10:37

@domkm good to hear! If it’s something you end up sharing let me know, I’ll be curious to see what solution you settled on simple_smile

zentrope23:10:14

I’ve got an attribute :event/attendees :ref :many isComponent and I want to replace it with a new set of values. I tried (in a tx) :event/attendees #{ … new entity ids … }, but it just adds the new ones without auto-retracting the old. Is there an explanation of how that should work?

zentrope23:10:51

I thought I saw an example out there where you could just assert the value of a component attribute and if the value is of type set it would do the right thing.

zentrope23:10:52

Argh! I know I saw that code fragment somewhere!

zentrope23:10:48

Maybe here: http://docs.datomic.com/transactions.html#cardinality-many-transactions. Guess I saw something I wanted to see, now what was there, alas.

zentrope23:10:48

I guess the option is to use a db function of some sort, or just read in the old values, diff against the new stuff, and assert/retract to taste.