Instantly share code, notes, and snippets.

@oleander /fail.md Secret
Last active Sep 29, 2015

Embed
What would you like to do?
ember.debug.js:29661 Error: Assertion Failed: The id 1 has already been used with another record of type ember-fail@model:user:.
    at new Error (native)
    at Error.EmberError (http://localhost:4200/assets/vendor.js:25605:21)
    at Object._emberMetalCore.default.assert (http://localhost:4200/assets/vendor.js:15745:13)
    at ember$data$lib$system$store$$Service.extend.buildInternalModel (http://localhost:4200/assets/vendor.js:73147:15)
    at ember$data$lib$system$store$$Service.extend.createRecord (http://localhost:4200/assets/vendor.js:71812:34)
    at http://localhost:4200/assets/ember-fail.js:156:35
    at tryCatch (http://localhost:4200/assets/vendor.js:60951:14)
    at invokeCallback (http://localhost:4200/assets/vendor.js:60966:15)
    at publish (http://localhost:4200/assets/vendor.js:60934:9)
    at publishRejection (http://localhost:4200/assets/vendor.js:60869:5)
export default Ember.Route.extend({
  afterModel: function() {
    var self = this;
    var ids = [];
    for (var i = 40; i > 0; i--) { ids.push(i); }

    // Run 2 times
    for (var n = 2; n > 0; n--) {
      ids.forEach(function(id) {
        self.store.findRecord("user", id).then(function(user) {
          console.info("User already exists with id ", user.get("id"));
        }).catch(function() {
          var user = self.store.createRecord("user", {
            name: "Joe",
            id: id
          });

          console.info("User was created with id", user.get("id"));
        })
      });
    }
  }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment