Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixed error when committing a created record #48

Closed
wants to merge 2 commits into from

5 participants

@kyptin

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.

kyptin added some commits
@kyptin kyptin 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.
61ec184
@kyptin kyptin Merge branch 'master' of github.com:emberjs/data 094a252
@dmathieu

+1, this definitely fixes the problem. Thanks @kyptin

@rvega

This works for me as well +1

@kyptin

Glad to hear it, dmathieu and rvega; thanks for speaking up. :-)

@mimay

Fix works ok for me as well!

@tomdale
Owner

@kyptin This actually seems like a bug in Ember's state manager, which I think we fixed here: emberjs/ember.js@df0c49a. Can you test to see if the issue is resolved after updating to that version of Ember.js?

@kyptin

@tomdale Thanks for the response. I can confirm that this is no longer an issue on the latest HEAD's of emberjs/ember and emberjs/data. So I'm going to close the issue now.

The funny thing is, when I started bisecting to try to nail down which commit fixed the issue, it was not your commit but commit 68ded658b1baa1801effd2094ac526b014609372 (merged in commit 8dbf37df517764fe129029d04a056bd38f4cfd4d), from January 6—which is actually a week or two before I created this issue. The same commit fixed the issue both for the current HEAD of emberjs/data as well as for the commit from which I originally forked (7a3a349). Apparently I wasn't running the latest emberjs/ember code when I found this issue. Whoops!

@kyptin kyptin closed this
@pangratz pangratz referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 17, 2012
  1. @kyptin

    Fixed error when committing a created record:

    kyptin authored
    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.
Commits on Jan 24, 2012
  1. @kyptin
This page is out of date. Refresh to see the latest.
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) {
Something went wrong with that request. Please try again.