2

the page load starts at when a user is viewing a user's profile. And he makes some action and my code does ajax call to update it's user type-

App.UserController = Ember.ObjectController.extend
  convert: ->
    $.get '/api/user/convert_to_client/' + id, (response) ->
      self.set('user_type', response.user.user_type)     

But whenever i go to the user listing table and Ember tries to fetch all the users from the UsersRoute:

module.exports = App.UsersRoute = Em.Route.extend
    model: ->
      App.User.find({}).then (response) ->     
        self.controllerFor('users').set('content', response)       

Then i end up getting all errors similar to these:

Error Attempted to handle event `loadedData` : Object not updated after deleteRecord

Update ember-data model\

I think this article here explains the issue -

http://www.thomasboyt.com/2013/05/01/why-ember-data-breaks.html

Uncaught Error: Attempted to handle event loadedData on while in state rootState.loaded.updated.uncommitted. Called with {}

What this means is that you're trying to do something to the record that it can't do in its current state. This often happens when trying to update a record that's currently saving or when trying to render a property on an object that's been deleted.

But note that when its the other way around, I first go to the user listing table, and then go and view a user's profile, update the user - this error never comes out.

Edit:

Sample response from users:

{
  users: [
    {
       _id: 521e1112e8c5e10fb40002a0
        ..
    }
   ]
}

and for a single user:

{
  user: {
    _id: 521e1116e8c5e10fb40004ca
  }
}
Community
  • 1
  • 1
David
  • 4,235
  • 12
  • 44
  • 52
  • Could you post the exact error you are getting? – chopper Sep 22 '13 at 20:41
  • this is the error - Uncaught Error: Attempted to handle event `loadedData` on while in state rootState.loaded.updated.uncommitted. Called with undefined – David Sep 23 '13 at 15:05
  • Could you also include you model definition as well as the JSON responses for the two requests? – chopper Sep 23 '13 at 18:24
  • Ive edited my post on a few places - first i added the sample json result, which conforms to the format of ember data. 2nd - scroll all the way up, you will see m ajax call is made inside the UserController. – David Sep 23 '13 at 23:02

2 Answers2

0

You should set up your controller in the `setupController' hook like this:

model: function() {
   return App.User.find({});
},
setupController: function(controller, model) {
   controller.set('content', model);
}

Not sure if that's the only problem though. Could you post more information on the error you are getting?

chopper
  • 6,649
  • 7
  • 36
  • 53
  • I think you meant putting that on UserRoute right? Didn't help - also have it on UsersRoute. – David Sep 23 '13 at 15:06
  • This should be in your User*s* route, because you fetch _all_ users in your model hook – chopper Sep 23 '13 at 18:23
  • i also have them in both places. to summarize my issue. I want to update a single model's data, then go to the model listing page without any errors. – David Sep 23 '13 at 23:04
0

You should use store.update to update the record in the store without changing the record's state (instead of using set on the record) e.g.

$.get '/api/user/convert_to_client/' + id, (response) =>
  @store.update 'user', id: id, user_type: response.user.user_type

Or, if you structure your response correctly, just:

@store.update 'user', response.user

Note: update may not be available in older versions of EmberData

gerry3
  • 21,420
  • 9
  • 66
  • 74