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

Flushing child session merges child model with parent model even if PUT request failed #22

Closed
denisnazarov opened this issue Jul 19, 2013 · 2 comments
Labels

Comments

@denisnazarov
Copy link

I am following the following convention from the docs:

var post = session.load(App.Post, 1);

var childSession = session.newSession(); // this creates a "child" session

var childPost = childSession.load(App.Post, 1); // this record instance is separate from its corresponding instance in the parent session

post === childPost; // returns false, they are separate instances
post.isEqual(childPost); // this will return true

childPost.title = 'something'; // this will not affect `post`

childSession.flush(); // this will flush changes both to the backend and the parent session, at this point `post` will have its title updated to reflect `childPost`

If the PUT request fails after doing childSession.flush(), post is still updated to match the changes to childPost.

I am using a child session to update a model (it is a user settings page) so it doesn't change in real time in another part of the UI. This is very easy using child sessions and child models (compared to ember-data), but the changes shouldn't merge if the backend PUT fails.

Any workarounds?

@ghempton
Copy link
Contributor

Good find, this should definitely not be the case. I am planning on a big code spike on epf this weekend and will fix this.

For the short term as a workaround, you could "rollback" the parent session's record. This would mean something like the following:

var model = ...
var shadow = session.getShadow(model);
shadow.copyAttributes(model);
// here the model will be in its original state before the child session flushed

@ghempton
Copy link
Contributor

The semantics here have changed and should address this. See #59.

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

No branches or pull requests

2 participants