0
votes

In ember-data v0.14 (pre beta). You could do simply extend model functionality to add extra api calls, like voting on a post.

// ember-data v0.14
App.Post.reopenClass({
  vote: function(post_id) {
    return console.log('vote');
  }
});

But after ember-data beta, this doesn't work anymore. So i think the best place to put this code is in App.PostAdapter. But when i tried to extend from App.ApplicationAdapter.extend it didn't work.

// ember-data beta (doesn't work)
App.PostAdapter = App.ApplicationAdapter.extend({
  vote: function(post_id) {
    return console.log('vote');
  }
});

Any ideas on what am I doing wrong? and if you have a better suggestion on where should I put these kind of calls, I would really appreciate it. Thanks in advance

1

1 Answers

2
votes

You should just be able to include the method in your normal class definition (using extend) and then call it on any live object.

App.Post = DS.Model.extend({
  vote: function(post_id) {
    return console.log('vote');
  }
});

Then somewhere else, say your PostController, you'd have something like this (assuming your PostRoute is doing the normal things):

App.PostController = Ember.ObjectController.extend({
  actions:{
    recordVote : function(){
      this.get('content').vote();
    }
  }
});