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

Store is not checking duplication #4626

Closed
trevorrjohn opened this issue Oct 24, 2016 · 1 comment
Closed

Store is not checking duplication #4626

trevorrjohn opened this issue Oct 24, 2016 · 1 comment

Comments

@trevorrjohn
Copy link
Contributor

trevorrjohn commented Oct 24, 2016

My issue surrounds the fact that record.save does not check if the new record being saved is already in the database.

The scenario for this is when I am saving a new record without an id, and some other process comes along and creates the record, when the server returns the response, the new record is saved along with the duplicate.

var record = this.store.createRecord('user');
// Save takes long time
record.save(user => console.log(this.store.peekAll('user').mapBy('id')) /* ['userId', 'userId'] */);
// while save is being performed and no response yet
this.store.createRecord('user', { id: 'userId' });

This is a bit of a confusing situation, but we have web sockets that also manage our store and we are getting a new record event before the server returns with the response. My understanding is that when we get the web socket event, since there is no record with that id saved yet, it goes ahead and creates the new record. Then when the server returns the response, it never checks the store again to see if that id exists. Thus creating two records in the store with the same id.

Let me know if there are questions.

@wecc
Copy link
Contributor

wecc commented Oct 24, 2016

@trevorrjohn Yes, unfortunately this has been a known limitation of Ember Data for some time. I'm happy to report that there's an RFC with a proposal to this problem over at emberjs/rfcs#173. Feel free to have a look and leave any feedback over there. I'm closing this issue as a dupe of #1829 where this has been tracked previously.

@wecc wecc closed this as completed Oct 24, 2016
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

No branches or pull requests

2 participants