Help! store.pushPayload is driving me insane

Do you have any ideas why this code isn’t working?


App.ApplicationSerializer = DS.ActiveModelSerializer;


App.Room = DS.Model.extend({
  name         : DS.attr(),
  url          : DS.attr(),
  created_at   : DS.attr(),
  updated_at   : DS.attr(),
  messages: DS.hasMany('message',{async:true})
App.Room.FIXTURES = [{
  id: 1,
  name: 'Lobby',
  url: 'lobby',
  messages: [1,2]


App.RoomRoute = Ember.Route.extend({
  beforeModel: function(transition) {
    var myRoom = {"room":[{"id":1,"url":"kitchen","name":"Kitchen","message_ids":[]}],"message":[]};
    store.pushPayload('room', myRoom);

When I run this payload, nothing changes. The “room” with id 1 set in the fixture hasn’t changed.

Plesae help me stay sane :slight_smile:

Just a wild guess, but I think the root keys of your payload should be pluralized.

Either that or he should remove the square brackets to push a single item.

like this

var myRoom = {"rooms": [ {"id":1,"url":"kitchen","name":"Kitchen","message_ids":[]} ]};
store.pushPayload('room', myRoom);

or just push a single record

var myRoom = {"room": {"id":1,"url":"kitchen","name":"Kitchen","message_ids":[]}};
store.push('room', myRoom);

I see, is it a rule to pluralize them like that?

Also, push payload will only make local changes.

You should use store.find to get the model. Make changes to the model then use

@billybonks I guess it depends on the adapter? The adapter can implement pushPayload? Or can it?

it would depend on the store, if you customised the Store,pushPayload then you could get that behaviour, but I wouldn’t suggest going against the grain unless you can give a good reason for it :smile:

How its working for me

var user = {id: 1, email: "", firstname: "Ringo"};
var normalizedUser = @store.serializerFor('user').normalize(App.User, user);  
//normaly 'user', instead of App.User, but that doesnt work for me
@store.push('user', normalizedUser)
@store.all('user').get('length') // returns 1