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

Reject CREATE with a duplicate id #510

Merged
merged 2 commits into from Mar 19, 2015
Merged

Reject CREATE with a duplicate id #510

merged 2 commits into from Mar 19, 2015

Conversation

bajtos
Copy link
Member

@bajtos bajtos commented Mar 16, 2015

Modify the memory connector to reject requests to create a record with a duplicate id.

Add a unit-test to verify this behaviour across all connectors.

Connect to strongloop/loopback#986

/to @raymondfeng please review

@bajtos bajtos added the #review label Mar 16, 2015
@bajtos bajtos changed the title Reject CREATE with duplicate ids Reject CREATE with a duplicate id Mar 16, 2015
@@ -210,6 +210,11 @@ Memory.prototype.create = function create(model, data, callback) {
if(!this.collection(model)) {
this.collection(model, {});
}

if (this.collection(model)[id]) {
return callback(new Error('Duplicate entry for ' + model + '.' + idName));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make the callback inside process.nextTick so that the async expectation is guaranteed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, fixed.

Miroslav Bajtoš added 2 commits March 16, 2015 18:26
Modify the memory connector to reject requests to create a record
with a duplicate id.

Add a unit-test to verify this behaviour across all connectors.
Before this commit, the following code would not work:

    Change.updateOrCreate({...}, function(err, ch) {
      // somewhere later, modify "ch" and save the changes
      ch.save(cb);
    });
@bajtos
Copy link
Member Author

bajtos commented Mar 16, 2015

LGTY now?

@bajtos bajtos added this to the #Epic: Offline Sync V1 milestone Mar 18, 2015
@raymondfeng
Copy link
Contributor

LGTM

bajtos added a commit that referenced this pull request Mar 19, 2015
@bajtos bajtos merged commit ae3dc3c into master Mar 19, 2015
@bajtos bajtos removed the #review label Mar 19, 2015
@bajtos bajtos deleted the fix/duplicate-create branch March 19, 2015 16:37
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 this pull request may close these issues.

None yet

2 participants