Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed error when committing a created record:

When creating a record and calling commit on the store, I get the
following error:

    Uncaught TypeError: Object (subclass of DS.State) has no method 'enter'

Here is some code that exhibits this error:

    window.App = Ember.Application.create();

    App.store = DS.Store.create({
      adapter: DS.Adapter.create({
        createRecord: function() {
          console.log('created record');
        }
      }),
    });

    App.Person = DS.Model.extend({
      name:       DS.attr('string'),
    });

    App.store.createRecord(App.Person, {name: 'Jeff T.'});
    App.store.commit();

The problem was that we were attempting to enter a state class, rather
than a state instance.  This was caused by calling `DS.State.extend()`
within another `DS.State.extend()` call.
  • Loading branch information...
commit 61ec1843826efe4dc6e85151f0384b94193f8d49 1 parent 7a3a349
@kyptin authored
Showing with 34 additions and 28 deletions.
  1. +34 −28 packages/ember-data/lib/system/model.js
View
62 packages/ember-data/lib/system/model.js
@@ -78,42 +78,48 @@ var DirtyState = DS.State.extend({
willCommit: function(manager) {
manager.goToState('saving');
- },
+ }
+});
- saving: DS.State.extend({
- isSaving: true,
+var createDirtyState = function(params) {
+ var paramsWithSubstates = jQuery.extend({}, params, {
+ saving: DS.State.create({
+ isSaving: true,
- didUpdate: function(manager) {
- manager.goToState('loaded');
- },
+ didUpdate: function(manager) {
+ manager.goToState('loaded');
+ },
- wasInvalid: function(manager, errors) {
- var model = get(manager, 'model');
+ wasInvalid: function(manager, errors) {
+ var model = get(manager, 'model');
- set(model, 'errors', errors);
- manager.goToState('invalid');
- }
- }),
+ set(model, 'errors', errors);
+ manager.goToState('invalid');
+ }
+ }),
- invalid: DS.State.extend({
- isValid: false,
+ invalid: DS.State.create({
+ isValid: false,
- setProperty: function(manager, context) {
- setProperty(manager, context);
+ setProperty: function(manager, context) {
+ setProperty(manager, context);
- var stateName = getPath(this, 'parentState.stateName'),
- model = get(manager, 'model'),
- errors = get(model, 'errors'),
- key = context.key;
+ var stateName = getPath(this, 'parentState.stateName'),
+ model = get(manager, 'model'),
+ errors = get(model, 'errors'),
+ key = context.key;
- delete errors[key];
+ delete errors[key];
- if (isEmptyObject(errors)) {
- manager.goToState(stateName);
+ if (isEmptyObject(errors)) {
+ manager.goToState(stateName);
+ }
}
- }
- })
-});
+ })
+ });
+
+ return DirtyState.create(paramsWithSubstates);
+};
var states = {
rootState: Ember.State.create({
@@ -173,7 +179,7 @@ var states = {
manager.goToState('deleted');
},
- created: DirtyState.create({
+ created: createDirtyState({
stateName: 'created',
isNew: true,
@@ -182,7 +188,7 @@ var states = {
}
}),
- updated: DirtyState.create({
+ updated: createDirtyState({
stateName: 'updated',
notifyModel: function(model) {
Please sign in to comment.
Something went wrong with that request. Please try again.