I have several models which have their own url/api they can fetch.
I would like to keep them in a collection.
- does it sound like a good idea?
- how would you fetch them? (I'm thinking just to get the model I want to update from the collection then fetch it)
Let me know what you think, if you have any theoretical reading/advise.
A collection can contain any raw objects or any models derived from a
Backbone.Model
. Fetching a collection makes sense only if you have an API endpoint which returns an array of objects.If you want to fetch a specific model, you can keep a reference to it, or just
get
it inside your collection, and then callfetch
on it.It can cause problems when you have
id
collisions, where identical ids are considered the same model and are merged together.Ways to avoid
id
collisions:cid
.id
attribute composed of identifying data, like prepending thetype
attribute. (book1
,note1
).A way to make a multi model collection is to use the
model
property as a function. Though it doesn't preventid
collision by default.See similar questions about multiple models in a collection: