3
votes

I'm upgrading an Ember application from 1.11 to 1.13.2

I've got a blog initially displaying 5 blog-entries. They are loaded in the model with this route:

import Ember from 'ember';
export default Ember.Route.extend({

  model: function() {
    return this.store.find('post', {limit: 5});
   }
});

There's a button to load more entries in the controller:

loadMore: function() {
  var self = this
  this.store.find('post', {limit: 5,
                           skip: 5})
    .then(function(posts) {
      self.incrementProperty('page');
      self.get('model').addObjects(posts);
    });
}

However since upgrading I get this error after loadMore was executed:

TypeError: internalModel.getRecord is not a function
    at Ember.ArrayProxy.extend.objectAtContent (record-array.js:84)
    at _emberRuntimeSystemObject.default.extend.objectAt (ember.debug.js:35919)
    at _emberRuntimeSystemObject.default.extend.objectAtContent (ember.debug.js:35780)
    at _emberRuntimeSystemObject.default.extend.objectAt (ember.debug.js:35919)
1
loadMore code is in the rote or in the controller? - artych
It's in the controller - Hedge
Ember is in a fever preparing to the 2.0 release. Try upgrading Ember and Ember Data to 1.13.4, this might help. - Andrey Mikhaylov - lolmaus
I'm seeing the same issue in Ember Data 1.13.5 - Matt Jensen
Hey was able to fix a similar issue this with this code: posts.addObject(post._internalModel) It is obviously just a single record added and huge hack, but it did fix the same error message. - Matt Jensen

1 Answers

1
votes

You're using the ember-cli it comes loaded with babel, might as well use ES6 syntax, load more becomes the following:

loadMore() {
  this.store.find('post', {
    limit: 5,
    skip: 5
  })
    .then((posts) => {
      this.incrementProperty('page');
      let model = this.get('model');
      posts.forEach(model.pushObject.bind(model));
    });
}