Bootstrapping ember-data from nested JSON

Hello. I have a big problem. Here is my ember-data schema:

App.WUser = DS.Model.extend({
  list: DS.hasMany('App.User')
});

App.User = DS.Model.extend({
  username: DS.attr('string'),
  name: DS.attr('string'),
  surname: DS.attr('string'),
  user: DS.belongsTo('App.WUser')
});

I would populate my two tables using this JSON, from my server:

var obj = {
  id: 0,
  list: [
         {id:0, username:'user_1',name:'Name1',surname:'Surname1'},
         {id:1, username:'user_2',name:'Name2',surname:'Surname2'},
        ]
}

I cannot find the function loadMany. I tried using App.Store.loadMany( … ); or DS.Store.loadMany( … );

But it seems there are no method called loadMany…

I am using ember version: → Ember.VERSION : 1.0.0-rc.2 Ember data version: → Last commit: 57d6c01 (2013-03-18 11:27:29 -0700)

Thanks for replies!

Mattia

EDIT: however: should I user load() or loadMany() ? Thanks

store = DS.get(‘defaultStore’)

store.loadMany(App.User, [ { … } { … } ])

1 Like

Thanks for reply!! This is the way! But, maybe my Model is not setted correctly and for some reasons I cannot import my JSON… I have write a post at StackOverflow

As show in the StackOverflow post, i have:

DS.SocketAdapter.map('App.User', {
    primaryKey: 'username'
});


DS.SocketAdapter.map('App.WUser', {
  list: {embedded: 'always'}
});