blaineh
blaineh

Reputation: 2323

Cannot save model when using ember render helper

I'm rendering a model into a parent template like this:

{{render "teacher" teacher}}

Here's it's controller:

App.TeacherController = Ember.ObjectController.extend(App.EditableModelMixin, {
    actions: {
        saveTypes: function() {
            if (this.get('model')) console.log('Exists');
            console.log(this.get('model'));
            console.log(this.get('model').get('isFulfilled'));
            this.get('model').save();
        }
    }
});

Here's the output when this method is called:

Exists
Class {isFulfilled: true, toString: function, constructor: function, reason: null, isPending: undefined…}
true
Uncaught TypeError: Object [object Object] has no method 'save'

This way of doing things has had no problems for me before. It only seems to happen when I use render.

Update

Here's a screen shot of me looking at the TeacherController in Ember Inspector:

TeacherController

And another of just my view hierarchy:

View

Upvotes: 2

Views: 134

Answers (1)

Kingpin2k
Kingpin2k

Reputation: 47367

It appears as if that model is a PromiseObject (from an async mapping). Promise objects are an extension of Ember.ObjectProxy which will proxy property calls down to the real model if it exists, but the methods aren't proxied.

   var modelPromise = this.get('model');
   modelPromise.then(function(actualModel){
     actualModel.save();
   });

Upvotes: 2

Related Questions