horizon icon indicating copy to clipboard operation
horizon copied to clipboard

collection.store(object) mutates date values

Open intellix opened this issue 8 years ago • 4 comments

Server version: 1.1.3 Client version: 1.1.3

I'm using ng2 and piping a date object into a particular format within my view. Upon using store, the date is replaced by Horizon/RethinkDB metadata within the original object so my view dies. I'm currently getting around this by copying the object with: Object.assign({}, o)

Example:

var o = {
  name: 'test',
  created: new Date()
};
horizon('things').store(o).subscribe(() => {
  console.log(o.created); // {$reql_type$: "TIME", epoch_time: 1465318800, timezone: 'Z' }
});

intellix avatar Jul 07 '16 13:07 intellix

Shoot! Deserialize should definitely not mutate, that was a bad call on my part (trying to be prematurely efficient :/)

deontologician avatar Jul 07 '16 22:07 deontologician

How do we work around this? Is there an easy way to convert this object to a regular Date object? Like, maybe, new Date(o.created.epoch_time) ? Or do you suggest that we don't store Date objects, but instead store timestamps, date.getTime()?

tailsu avatar Sep 29 '16 08:09 tailsu

Maybe copy the object before storing it, and copy the returned id back to the original copy? Hairy...

tailsu avatar Sep 29 '16 09:09 tailsu

The same problem occurs with collection.update.

tailsu avatar Sep 29 '16 09:09 tailsu