Skip to content
This repository was archived by the owner on Apr 22, 2021. It is now read-only.

Conversation

@stephenr85
Copy link

In instances where we want to inject models into a page from the server, it makes sense to use Model.all().add([...]), but the model instances were not being registered because they were using the default Backbone.Collection.

I have modified it to use a pre-attached Model.Collection class (allowing extra customization/configuration), or automatically extending the Backbone.Collection's model() method to use Model.create().

In instances where we want to inject models into a page from the server, it makes sense to use Model.all().add([...]), but the model instances were not being registered because they were using the default Backbone.Collection. 

I have modified it to use a pre-attached Model.Collection class (allowing extra customization/configuration), or automatically extending the Backbone.Collection's model() method to use Model.create().
@braddunbar
Copy link
Contributor

Hi @stephenr85! Models are added to the all collection via create, which instantiates models with the correct constructor. Any reason not to just use MyModel.create(...)?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants