title: How can I correctly implement parse in a Backbone model to include collections?
body: <p>I have a backbone model called <code>Member</code> - this contains membership data such as first name, last name, email, phone, etc. It also includes multi-valued fields that I need to keep as collections - these are <code>Degrees</code> and <code>Affiliations</code>.</p>
  
  <p>The issue I am running into when calling the <code>fetch()</code> method in my model is that there's an impedance mismatch of sorts between a basic array, and the collection objects I have in my model. Since <code>parse</code> by definition is supposed to return a hash to be used in <code>set</code> rather than actually setting values, it is impossible for me to set my collections this way. For instance - if I return a JavaScript object for <code>Degrees</code> that looks something like the following: <code>{degrees: [{id: 1, title: "PhD"}]}</code>, then this converts my <code>degree</code> collection into a flat array. Here is my code:</p>
  
  <pre><code>window.Models.Member = Backbone.Model.extend({
  
      url: '/api/member',
  
      initialize: function() {
  
          _.bindAll(this);
  
          this.set('degrees', new window.Collections.DegreesList());
  
          this.fetch();
  
      },
  
      parse: function(response) {
  
          var setHash = {};
  
          setHash.first_name = response.first_name;
          setHash.last_name = response.last_name;
          setHash.office_phone = response.office_phone;
  
          // When this is run, this.get('degrees') will now return a flat array rather than a DegreesList collection
          setHash.degrees = _(response.degrees).each(function(item) { 
                  return {id: item.id, title: item.title} 
          });
  
          return setHash;
  
      }
  
  });
  </code></pre>
  
  <p>I could manually set the collections in my parse function, but that seems like its subverting the Backbone way, and hacky.</p>
  
  <p>EDIT: I've temporarily solved the problem by doing the following:</p>
  
  <pre><code>parse: function(response) {
  
      var setHash = {};
  
      setHash.first_name = response.first_name;
      setHash.last_name = response.last_name;
      setHash.office_phone = response.office_phone;
  
      this.get('degrees').reset( response.degrees );
  
      return setHash;     
  }
  </code></pre>
  
  <p>I doubt this is the optimal solution, but it certainly works for now. I'm open to better suggestions.</p>