title: Populating ember-data table from WebSocket
body: <p>My backend is sending me this JSON (example):</p>
  
  <pre><code>{
    id: 0,
    list: [
           {username:'user_1', name:'Name1', surname:'Surname1', user:0},
           {username:'user_2', name:'Name2', surname:'Surname2', user:0},
          ]
  }
  </code></pre>
  
  <p>I have the necessity to bootstrap my table <code>App.WUser</code> with that type of JSON. Data comes via WebSocket. My Ember.js schema is defined as follow:</p>
  
  <pre><code>App.WUser = DS.Model.extend({
    list: DS.hasMany('App.User')
  });
  
  App.User = DS.Model.extend({
    username: DS.attr('string'), // primary key
    name: DS.attr('string'),
    surname: DS.attr('string'),
    user: DS.belongsTo('App.WUser')
  });
  </code></pre>
  
  <p>I writed my custum Adapter for WebSocket implementation. Note that <code>App.WebSocketConnection</code> is a Mixin contains the connection handler (see the last snippet).</p>
  
  <pre><code>DS.SocketAdapter = DS.RESTAdapter.extend(App.WebSocketConnection, { 
    socket: undefined,
  
    init: function() {    
      socket = this.getSocket(); // activate WS connection (see Mixin)
      this._super();
    },
  
    find: function (store, type, id) {
       // empty block    
    },
  
    findAll: function (store, type) { 
      // empty block
    },
  
    createRecord: function(store, type, record) {
      // code not relevant
    }
  });
  
  
  
  DS.SocketAdapter.map('App.User', {
      primaryKey: 'username'
  });
  
  
  DS.SocketAdapter.map('App.WUser', {
    list: {embedded: 'always'}
  });
  </code></pre>
  
  <p>My Store</p>
  
  <pre><code>App.Store = DS.Store.extend({
    revision: 12,
    adapter: DS.SocketAdapter.create({})
  });
  </code></pre>
  
  <p>My Mixin:</p>
  
  <pre><code>App.WebSocketHandler = Ember.Object.extend({
    uri: 'ws://localhost:8080/App/atmosphere/chat/all',
    ws: ,
  
    init: function() { 
      this.ws = new WebSocket(this.uri));                                                                 
  
      // callbacks
      this.ws.onopen = function() {
        console.log('Connection established /all');
      };
      this.ws.onclone = function() {
        console.log('Connection closed /' + 'all');
      };
      this.ws.onmessage = function(data) {
        alert('New JSON message from server /all ' + data);    // &lt;---- ???
      };
  
      this._super();
    },
  
    send: function(data) { 
  
  
      // not relevant method... this method simply send a message to the server
      /* 
     var some = ...
  
      this.ws.send( JSON.stringify( some ) );
      */
    }
  
  });
  </code></pre>
  
  <p>Searching on Google, I reached to write this piece of code:</p>
  
  <pre><code>var JSONfromWebSocket = {
    id: 0,
    list: [
       {username:'user_1', name:'Name1', surname:'Surname1', user:0},
       {username:'user_2', name:'Name2', surname:'Surname2', user:0},
      ]
  };
      var store = DS.get('defaultStore');
      store.loadMany(App.WUser, [0], JSONfromWebSocket); // should I specify the [0] id?
  
      (?) this.didCreateRecords(store, App.WUser, records(?), undefined); // is it a neccessary line?
  </code></pre>
  
  <p>Questions:</p>
  
  <ol>
  <li>Where I put my piece of code?</li>
  <li>Is my piece of code correct? Is it the correct way to boostrap data?</li>
  <li>Is it correct the usage of custum primaryKey?</li>
  <li>Considering my custum ID of table <code>App.User</code>; is it correct the call to loadMany() function?</li>
  <li>Note that the JSON is coming from <strong>onmessage</strong> callback (see line <code>`// &lt;---- ???</code> ). How to call one  of functions - and which - (i.e.createRecords) inherited by the Adapter, passing it the JSON data?</li>
  </ol>
  
  <p>I am a bit confused, but I hope i am in the right way... My problem is to glue the pieces of my code!</p>
  
  <p>Thanks for patience!</p>
  
  <p>Mattia</p>