0
votes

I have an ember-cli project, and I'm trying to get to ember 2.0. I know the idea is to remove all deprecation warning before upgrading, but I don't know what to do about this one:

DEPRECATION: The default behavior of shouldReloadAll will change in Ember Data 2.0 
to always return false when there is at least one "foo" record in the store. 
If you would like to preserve the current behavior please override shouldReloadAll 
in your adapter:application and return true. 
[deprecation id: ds.adapter.should-reload-all-default-behavior]

This warning is related to a call that I make for this.store.findAll('foo') for example.

As far as I can understand, fixing this would involve change the behavior of either ember-data or ember-django-adapter.

Here is my (partial) package.json:

{
  "name": "my-app",
  "private": true,
  "devDependencies": {
    "ember-cli": "1.13.13",
    "ember-data": "1.13.15",
    "ember-django-adapter": "^1.1.1",
  }
}

Here is a some of my bower.json:

{
  "name": "my-app",
  "dependencies": {
    "ember": "1.13.11",
    "ember-data": "1.13.15",
    "ember-resolver": "~0.1.20",
  }
}

So, after reading a bit, I thought maybe I can just ignore this warning, and maybe the behavior of shouldReloadAll isn't all that important for my app.

I'll list my steps carefully, because I'm not very familiar with npm or bower, and I may well be doing something wrong.

  1. Change ember and ember-data to "~2.0.0" wherever they occur in package.json and ember.json
  2. npm uninstall ember-data
  3. bower uninstall ember-data
  4. bower uninstall ember
  5. npm cache clear
  6. bower cache clear
  7. npm install
  8. bower install

At this point it is telling me that I have installed [email protected] and [email protected]

I then run the application, and find the following error:

TypeError: str.replace is not a function
    at Object.func (ember.debug.js:35278)
    at Object.Cache.get (ember.debug.js:12867)
    at decamelize (ember.debug.js:35320)
    at Object.func (ember.debug.js:35235)
    at Object.Cache.get (ember.debug.js:12867)
    at Object.dasherize (ember.debug.js:35324)
    at ember$data$lib$system$normalize$model$name$$normalizeModelName (normalize-model-name.js:13)
    at ember$data$lib$serializers$json$serializer$$default.extend.modelNameFromPayloadKey (rest-serializer.js:426)
    at ember$data$lib$serializers$json$serializer$$default.extend._normalizePolymorphicRecord (rest-serializer.js:161)
    at rest-serializer.js:141onerrorDefault @ ember.debug.js:29661exports.default.trigger @ ember.debug.js:51067(anonymous function) @ ember.debug.js:52059Queue.invoke @ ember.debug.js:978Queue.flush @ ember.debug.js:1042DeferredActionQueues.flush @ ember.debug.js:838Backburner.end @ ember.debug.js:166Backburner.run @ ember.debug.js:288run @ ember.debug.js:19125hash.success @ rest-adapter.js:735fire @ jquery.js:3148self.fireWith @ jquery.js:3260done @ jquery.js:9314callback @ jquery.js:9718

The following versions are reported:

DEBUG: -------------------------------
vendor.js:15777 DEBUG: Ember      : 2.0.2
vendor.js:15777 DEBUG: Ember Data : 2.0.1
vendor.js:15777 DEBUG: jQuery     : 1.11.3
vendor.js:15777 DEBUG: -------------------------------
vendor.js:19380 Rendering application with bracketfun-web@view:toplevel: Object

PLEASE NOTE: This error doesn't seem related to the deprecation, in any explanation of the deprecation that I've received.

1
Did you try just doing what it said? Simply override the shouldReloadAll() method in your application adapter (which will extend the Django adapter) and just make it return true. The reason for the change is so that results are cached, and can be explicitly reloaded using this.store.findAll('foo', { reload: true }). - uberclops
@uberclops I guess I don't understand how to do that. I didn't think I had an application adapter. Could you explain to me how exactly I would override that method? - Eric Wilson
@uberclops I've now tried explicitly reloading, and still get the same error. - Eric Wilson

1 Answers

2
votes

You need to create your application adapter by using ember generate drf-adapter application from the command line. This should create the file app/adapters/application.js, to which you will add the override of shouldReloadAll(), and the end result should look something like this:

import DRFAdapter from './drf';

export default DRFAdapter.extend({
    shouldReloadAll() {
        return true;
    }
});

EDIT: replace error.

If you look at the stack trace and see where the error is coming from, you'll see it's originating from the serializer. It's struggling to get the model name from the payload. This is most likely due to the fact that you have not set up your application serializer.

You can generate the serializer using ember generate drf-serializer application. This will create the file app/serializers/application.js.

Remember Ember does not know to implicitly use an adapter / serializer by simply installing the add on, you need to tell it to use them by creating an application adapter and serializer.