ampersand-rest-collection
ampersand-rest-collection copied to clipboard
Fetching a model by id when model is dynamic
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?
I believe you are looking for ampersand-registry which allows you to lookup a model by type and id.
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.