save icon indicating copy to clipboard operation
save copied to clipboard

Expose `idType` in memory engine

Open domharrington opened this issue 10 years ago • 7 comments

Without this, the API between memory-backed services have a different API to save-mongodb services, which can cause test failures.

domharrington avatar Feb 24 '15 10:02 domharrington

What cases do you still need idType()?

serby avatar Feb 24 '15 10:02 serby

article-slug-listener performs a read on the service by firstly casting the _id. This works with a save-mongodb persistence, but not a memory engine.

domharrington avatar Feb 24 '15 10:02 domharrington

I don't think it is needed in that case.

serby avatar Feb 24 '15 10:02 serby

I was hoping to deprecate idType() but I'm unsure if there are still any valid use-cases

serby avatar Feb 24 '15 10:02 serby

The tests do appear to pass without the call to service.idType(). Maybe it isn't needed...

It looks as though castIdProperty is called on read which caters for that case: https://github.com/serby/save-mongodb/blob/master/lib/mongodb-engine.js#L95

The only other use case I can think is:

var ids = _.map([1, 2, 3], function (id) {
  return service.idType(id)
})

var query = { _id: { $in: ids } }

Would this be catered for?

domharrington avatar Feb 24 '15 11:02 domharrington

I think so. https://github.com/serby/save-mongodb/blob/master/lib/mongodb-engine.js#L71

serby avatar Feb 24 '15 11:02 serby

In which case, i dont think this is needed and idType() can be removed from save-mongodb as well.

domharrington avatar Feb 24 '15 14:02 domharrington