I\'ve kinda been struggling with this for some time; let\'s see if somebody can help me out.
Although it\'s not explicitly said in the Readme, ember-data provides somewh
this may seem to be an overly simple answer, but why not create a new transaction and add the pre-existing record to it? i'm also trying to figure out an error handling approach.
also you should probably consider writing this at the store level rather than the adapter level for the sake of re-use.
I tried Javier's answer, but I get "Invalid Path" when doing any record.set(...)
with the record in invalid state. What I found worked was:
// with the record in invalid state
record.send('becameValid');
record.set('someProperty', 'a valid value');
App.store.commit();
Alternatively, it seems that if I call record.get(...)
first then subsequent record.set(...)
calls work. This is probably a bug. But the above work-around will work in general for being able to re-commit the same record even without changing any properties. (Of course, if the properties are still invalid it will just fail again.)
I have a pending pull request that should fix this
https://github.com/emberjs/data/pull/539
Give a look at this gist. Its the pattern that i use in my projects.
https://gist.github.com/danielgatis/5550982
For some unknown reason, the record becomes part of the store default transaction. This code works for me:
var transaction = App.store.transaction();
var record = transaction.createRecord(App.Post);
record.set('someProperty', 'invalid value');
transaction.commit()
record.set('someProperty', 'a valid value');
App.store.commit(); // The record is created in backend
The problem is that after the first failure, you must always use the App.store.commit()
with the problems it has.