title: Converting JSON data to Backbone Model with child Collection
body: <p>I am working with a Playlist object which has some properties defining itself as well as a PlaylistItem collection.</p>
  
  <p>When I receive data from my server, I get its JSON response in my client-side success method:</p>
  
  <pre><code>success: function (data) {
      console.log("JSON data:", data);
  
      playlists = _.map(data, function (playlistConfig) {
          return new Playlist(playlistConfig);
      });
  
      ...
  }
  </code></pre>
  
  <p>Here, I convert my JSON data into Playlist objects. Each Playlist object is a Backbone.Model.</p>
  
  <p>Here's how my data looks:</p>
  
  <p><img src="https://i.stack.imgur.com/yRTqI.png" alt="enter image description here"></p>
  
  <p>And here's what the Playlist constructor looks like:</p>
  
  <pre><code>return function(config) {
      var playlist = new Playlist(config);
  
      return playlist;
  };
  
  var Playlist = Backbone.Model.extend({
      defaults: function() {
          return {
              id: null,
              userId: null,
              title: 'New Playlist',
              selected: false,
              position: 0,
              shuffledItems: [],
              history: [],
              items: Backbone.Collection.extend({
                  model: PlaylistItem
              })
          };
      },
      ...
  }
  </code></pre>
  
  <p>My problem:</p>
  
  <p>If I create a Playlist object with defaults, it initializes with an empty Backbone.Collection for PlaylistItem. However, if I create a Playlist object with an already-defined collection, I get a basic array and not a Backbone.Collection. This is because I am working with JSON data from the server which has not been converted to Backbone entities yet. That data is extended over the Playlist's defaults and overwrites the Backbone.Collection entity.</p>
  
  <p>What is a proper way to initialize with a populated Backbone.Collection? I could write code in Initializes which checks the type of my items array and if it is not a Backbone.Collection I could create a new Backbone.Collection and add the items to it and then replace the old array with the new one, but that seems really hoakey.</p>