Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember Data: how can I delete/unload a record that's stuck in the "inFlight" state?

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?

like image 274
PJC Avatar asked Jun 29 '13 12:06

PJC


2 Answers

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.

like image 159
Mike Grassotti Avatar answered Nov 16 '22 05:11

Mike Grassotti


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

record.send('becameInvalid');
record.unloadRecord();
like image 6
aceofspades Avatar answered Nov 16 '22 06:11

aceofspades