0

In my model I have some nested collections, the API returns some data, and this gets parsed into a model fine, however because my API returned arrays in objects some of my attributes tend to look like this when logged...

member: Array[2]

In my model I am doing the following...

initialize: function() {

    //Gets
    var members  = this.get('members');
    //this.unset('members');

    //Sets
    this.set('members', new App.Collections.Users(members));

},

Now the members field does not get set to the collection when a fetch is done, why is this? I would have thought in fetching a model I am instantiating one? At the moment I have to run model.initialize() after I have done my fetch, is there a way around this?

w5m
  • 2,286
  • 3
  • 34
  • 46
Udders
  • 6,914
  • 24
  • 102
  • 194

1 Answers1

0

members is already set after fetch. Also, initialize is NOT called after fetch.

If you want to perform any action after fetching, then something like this can be done :

myModel.fetch().done(function(){
    this.set('members',new App.Collections.Users(this.get('members'));
});
coding_idiot
  • 13,526
  • 10
  • 65
  • 116