Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping models and collections from fetch calls parse when it should not. #147

Open
steelsojka opened this issue Aug 12, 2014 · 3 comments

Comments

@steelsojka
Copy link

var MyModel = Backbone.AssociatedModel.extend({
    relations: [{
        type: Backbone.Many,
        key: "entities",
        collectionType: EntityCollection
    }],
    parse: function(res) {
         // This gets called twice. When the response comes back
         // and then when setting the `entities` key
         return res.entities;
    },
    url: "myUrl"
});

model = new MyModel();

model.fetch();

When backbone-associations calls set when creating the EntityCollection with the key of entities it passes the options from the fetch which Backbone automatically sets the parse option to true which calls the parse function when setting the collection. In this case this would throw an undefined error since parse is getting called with just the array.

I'm not sure if this is a Backbone specific issue or not. Has anybody else ran into this issue?

@steelsojka
Copy link
Author

After digging through the source code, I realized I can add options onto the relation. I'll try this and see if it works.

@steelsojka
Copy link
Author

My above comment did not work since the options passed in override relation options :(

@steelsojka
Copy link
Author

The problem is that passed in options still override relation options. https://github.com/dhruvaray/backbone-associations/blob/master/backbone-associations.js#L271

Should this be the other way around?

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

No branches or pull requests

1 participant