Skip to content

Fix blank modelName when collection uses generic BaseModel #151

@spikebrehm

Description

@spikebrehm

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.

Sample collection:

var BaseCollection = require('rendr/shared/base/collection');
module.exports = BaseCollection.extend({});

Solution: modelUtils.modelName should fall back to looking at model.collection.constructor.id if model.constructor.id is blank.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions