0

I have an Ember model I am saving to a database. When I call

model.save().then(function () {
  alert('Everything worked.');
}, function () {
  alert('Save failed.');
});

the record persists to the database, the network request to the API call that does the saving responds with a status code of 200 and a body of

{
  "id": 11,
  "send_date": "2014-12-01T23:20:31.821Z",
  "expiration_date": "2014-12-08T06:00:00.000Z",
  "message": "What is happening here",
  "url": null,
  "feature_id": null
}

and no errors appear in the console. Everything works perfectly, except that the rejection handler alert('Save failed.') is called every time. The success handler is never called. Why?


EDIT

The reason passed to the fail handler is this error:

column: 22
line: 11256
message: "undefined is not an object (evaluating 'factory.typeKey')"
sourceURL: "http://localhost:8080/bower_components/ember-data/ember-data.js"
stack: "modelFor@http://localhost:8080/bower_components/ember-data/ember-data.js:11256:22
        recordForId@http://localhost:8080/bower_components/ember-data/ember-data.js:10727:33
        deserializeRecordId@http://localhost:8080/bower_components/ember-data/ember-data.js:11692:38
        http://localhost:8080/bower_components/ember-data/ember-data.js:11670:30
        http://localhost:8080/bower_components/ember-data/ember-data.js:9456:24
        http://localhost:8080/bower_components/ember-data/ember-data.js:5295:37
        http://localhost:8080/bower_components/ember/ember.js:14899:24
        forEach@http://localhost:8080/bower_components/ember/ember.js:14741:18
        forEach@http://localhost:8080/bower_components/ember/ember.js:14897:21
        mapForEach@http://localhost:8080/bower_components/ember-data/ember-data.js:5302:29
        eachRelationship@http://localhost:8080/bower_components/ember-data/ember-data.js:9455:49
        normalizeRelationships@http://localhost:8080/bower_components/ember-data/ember-data.js:11666:28
        didSaveRecord@http://localhost:8080/bower_components/ember-data/ember-data.js:11125:40
        http://localhost:8080/bower_components/ember-data/ember-data.js:11905:28
        tryCatch@http://localhost:8080/bower_components/ember/ember.js:45817:24
        invokeCallback@http://localhost:8080/bower_components/ember/ember.js:45829:25
        publish@http://localhost:8080/bower_components/ember/ember.js:45800:25
        http://localhost:8080/bower_components/ember/ember.js:29071:17
        invoke@http://localhost:8080/bower_components/ember/ember.js:634:22
        flush@http://localhost:8080/bower_components/ember/ember.js:684:21
        end@http://localhost:8080/bower_components/ember/ember.js:147:32
        run@http://localhost:8080/bower_components/ember/ember.js:202:23
        apply@http://localhost:8080/bower_components/ember/ember.js:18384:31
        run@http://localhost:8080/bower_components/ember/ember.js:17001:19
        success@http://localhost:8080/bower_components/ember-data/ember-data.js:1879:24
        fire@http://localhost:8080/bower_components/jquery/jquery.js:2913:35
        fireWith@http://localhost:8080/bower_components/jquery/jquery.js:3025:11
        done@http://localhost:8080/bower_components/jquery/jquery.js:7400:25
        http://localhost:8080/bower_components/jquery/jquery.js:7822:17"

EDIT

I fixed the error for now by removing a belongsTo relationship from the Ember Data model. The relationship was for a feature that I was going to implement later, so I'm removing it for now. Guess I will cross that bridge when I get to it.

3
  • 2
    Could you try this: }, function(reason) alert(reason); }); ? Dec 2, 2014 at 1:16
  • 1
    Does the JSON response need to be namespaced with the model type? Dec 2, 2014 at 3:07
  • If you turn on "Pause on Caught Exceptions" in devtools you are likely to be able to see the problem in flagrante delicto.
    – user663031
    Dec 2, 2014 at 6:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.