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

Setting Collection.model to a factory function subtly breaks when Model.idAttribute is set #57

Open
apaleslimghost opened this issue May 14, 2014 · 3 comments

Comments

@apaleslimghost
Copy link
Contributor

Collection#set uses this.model.prototype.idAttribute to test if it can update models in place. If this.model is actually a factory function wrapping Model.create, then this.model.prototype.idAttribute is undefined, so set decides to remove every model then add them back. This causes a race condition in my ListView, and it trashes everything.

@apaleslimghost
Copy link
Contributor Author

I've worked around this by using a factory that copies across the model's prototype, along the lines of

 function(model) {
  function Factory() {
    return model.create.apply(model, arguments);
  }
  Factory.prototype = model.prototype;
  return Factory;
}

@braddunbar, unless you think this is something Supermodel should take into account, I'm going to close this issue?

Come to think of it, is there a reason the create logic can't be rolled into the constructor?

@wookiehangover
Copy link

bump

@TheBox193
Copy link
Contributor

Thanks @wookiehangover Will you be doing a pull request to Supermodel?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants