8

Say I am trying to save a Foo record to the back-end. For whatever reason, the back-end never returns (neither success nor failure).

From what I can see, it looks like foo stays in the "in flight" state. The problem with this state is it completely locks the record - you can't do anything on it (can't rollback, can't unload). I understand why it is like that (to try and keep things consistent). But is there something you can do about an edge case like this?

aceofspades
  • 7,568
  • 1
  • 35
  • 48
PJC
  • 997
  • 7
  • 21

2 Answers2

7

I've not tried this but you might find a solution by looking at ember-data's source code, specifically states.js: https://github.com/emberjs/data/blob/master/packages/ember-data/lib/system/model/states.js#L306-L351

Not sure there is a solid best practice here, but my best guess is that you can recover by sending becameInvalid to the model's stateManager.

Mike Grassotti
  • 19,040
  • 3
  • 59
  • 57
6

Building on Mike's suggestion, I ended up with the following:

record.send('becameInvalid');
record.unloadRecord();
Community
  • 1
  • 1
aceofspades
  • 7,568
  • 1
  • 35
  • 48