You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In ModelStore#set, we determine the cache key based on the type of model. This is done using modelUtils.modelName(model), which in turn looks at the id or name property of model.constructor.
Now, in the case where a collection does not specify a custom model class, it will just use BaseModel. A problem arises when ModelStore#set is called on a model of this collection, because its modelName will be blank (it's an empty string in Chrome, and undefined in IE because IE doesn't support constructor.name). So IE throws an error, and Chrome just uses a bad cache key, i.e. ":14" instead of "my_model:14", in the case where model.id = 14.
I like the idea of having a default id. A lot of things break when you have models without IDs.
I ran into that playing around with view create viewModels that worked fine until a page switch (when things are set and fetched from the stores). Took me a while to track it down and the solution was to do something weird like
defaults: {id: 'lolz'}
If it's so important an error should be thrown, or a default should provided. I think in this case a unique default is the right solution.
In
ModelStore#set
, we determine the cache key based on the type of model. This is done usingmodelUtils.modelName(model)
, which in turn looks at theid
orname
property ofmodel.constructor
.Now, in the case where a collection does not specify a custom model class, it will just use
BaseModel
. A problem arises whenModelStore#set
is called on a model of this collection, because itsmodelName
will be blank (it's an empty string in Chrome, and undefined in IE because IE doesn't supportconstructor.name
). So IE throws an error, and Chrome just uses a bad cache key, i.e.":14"
instead of"my_model:14"
, in the case wheremodel.id = 14
.Sample collection:
Solution:
modelUtils.modelName
should fall back to looking atmodel.collection.constructor.id
ifmodel.constructor.id
is blank.The text was updated successfully, but these errors were encountered: