ampersand-rest-collection icon indicating copy to clipboard operation
ampersand-rest-collection copied to clipboard

Fetching a model by id when model is dynamic

Open sabymike opened this issue 10 years ago • 2 comments

I have a particular collection that has a function for determining which model should be created instead of a model object as described in the documentation. However, I've run into an issue when fetchById is called for a model in that collection.

In the ampersand-collection-rest-mixins.js method fetchById() the line:

idObj[this.model.prototype.idAttribute] = id;

seems to assume that the model property will not be a generic function but instead some type of Ampersand-Model object. Has anyone run into this use case and if so what did they do to solve it?

sabymike avatar Oct 15 '14 20:10 sabymike

I believe you are looking for ampersand-registry which allows you to lookup a model by type and id.

brianberlin avatar Oct 18 '14 17:10 brianberlin

I ran into the same problem (https://github.com/AmpersandJS/ampersand-collection-rest-mixin/issues/14). I think the best workaround will be to use the collection's mainIndex as a fallback in this line. I will issue a PR soon.

bernharduw avatar Jan 22 '15 15:01 bernharduw