Skip to content
This repository has been archived by the owner on May 17, 2018. It is now read-only.

parseRecords getting called twice #71

Closed
JoshClose opened this issue Apr 10, 2013 · 7 comments
Closed

parseRecords getting called twice #71

JoshClose opened this issue Apr 10, 2013 · 7 comments

Comments

@JoshClose
Copy link

I have overridden parseRecords because the data being returned is an object with an array on it.

The data being returned:

{
   Data: []
}

Normally in backbone I would just do this:

parse: function(response) {
   return response.Data;
}

parseRecords is getting called twice. The first time it is giving me the data from the server, but the second time it gives me the array of models that I returned from the first call.

Is this expected behavior or am I doing something wrong? It seems odd to me.

I'm able to workaround it by doing this:

parseRecords: function(response) {
    return response.Data || response;
}
@wyuenho
Copy link
Member

wyuenho commented Apr 11, 2013

parseRecords shouldn't be called twice unless parse is being called twice. Did you set options.parse to true somewhere?

@JoshClose
Copy link
Author

No. The collection is really simple. I don't have the code in front of me at the moment and can put exact code tomorrow, but it looked something like this.

var MyCollection = Backbone.PageableCollection.extend({

    model: MyModel, // This may or may not be there.

    url: "/some/path",

    parseRecords: function(response) {
        return response.Data || response;
    },

    save: function() {
        return this.sync("update", this);
    }

});

I'm pretty sure that's all that's in there, but I will double check that tomorrow.

@JoshClose
Copy link
Author

The only thing I missed from the code above is mode: "client". The model property IS there also.

@JoshClose
Copy link
Author

I have this exact same thing somewhere else that doesn't have mode: "client" and parseRecords is only hit once in that case.

@nemeria
Copy link

nemeria commented Apr 15, 2013

Same issue with mode: "infinite".
And the second time parseRecords is called my models are nested in the attributes of new models.
For example on the second parseRecords I have :

models[0] = { 
    changing: fase, 
    _events: Object, 
    attributes: {
       changing: false,
       _events: object,
      attributes: {
          //right attributes
      }
    }
    ...
}

@wyuenho
Copy link
Member

wyuenho commented Apr 15, 2013

Can you see if you can reproduce this problem on Backbone 0.9.10?

@nemeria
Copy link

nemeria commented Apr 15, 2013

I think the issue comes from https://github.com/documentcloud/backbone/blob/master/backbone.js#L860

which was not present in the 0.9.10, i cannot test it, i have some errors before ^^

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