Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to reuse a transaction on an invalid record #457

Closed
javierav opened this issue Nov 2, 2012 · 2 comments
Closed

unable to reuse a transaction on an invalid record #457

javierav opened this issue Nov 2, 2012 · 2 comments

Comments

@javierav
Copy link

javierav commented Nov 2, 2012

I have customized the REST adapter so that I can catch backend errors using the store.recordWasInvalid method in ajax error callback.

When I do this:

// called before in other moment
// var user =  App.store.find(App.User, "1"); 
// user.get("transaction") === App.store.get("defaultTransaction")
var t = App.store.transaction();
t.add(user);
// App.user.get('transaction') === t
// set an invalid name
user.set("name", " ");
// do commit
t.commit();

The server respond with 422 http status code and the model go to loaded.updated.invalid state after the adapter call store.recordWasInvalid. Then I set a valid value:

user.set("name", "Javier");
// user.get("transaction") === App.store.get("defaultTransaction")

When I set a valid value and the record not have any errors, change its state from loaded.updated.invalid to loaded.updated.uncommited. Internally, in the state manager, the state loaded.updated.invalid has the exit property defined and inside perform the deletion of current transaction and translate the record to the store default transaction.

As the record has changed fields can not be moved to a new transaction. In this case, the solution would not move the record from the current transaction, allowing transaction to be commited again.

Related issue in stackOverflow: http://stackoverflow.com/questions/11054868/whats-the-standard-pattern-for-ember-data-validations-invalid-state-becamein

@cyril-sf
Copy link
Contributor

I'm preparing a pull request to try to use recordIsMoving instead of recordBecameClean in the exit function of the invalid state.

Any thoughts about that ( as I don't know the implications of such a change )?

@wagenet
Copy link
Member

wagenet commented Jan 9, 2013

Closing in favor of further discussion on #539.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants