Passing classes to the store has been removed with Ember 2.0.1 and Ember-data 2.0


#1

I am using Ember 2.0.1 with Ember-data 2.0 and default the default RESTSerializer generated by ember-cli. I know this question has been asked to many places before (which none have real answers) but no solutions have been working for me yet.

I have this model hook for a user model :

export default Ember.Route.extend({
    model() {
	return this.store.findAll('user');
    }
});

Router is the following :

Router.map(function() {
  this.route('users', { path: '/' }, function() {
    this.route('user', { path: '/:user_id' }, function(){
	this.route('conversations', { path: '/'}, function(){
		this.route('conversation', { path: '/:conversation_id' });
	});
    });
  });
}); 

For example, going to /conversations/4 transitions to users.user.conversations. My relations are defined in my models. In the user model I have a DS.hasMany(‘conversation’) conversations attribute set with { embedded: ‘always’ }. Returned JSON looks like this :

{"conversations":[
    {
     "id":183,
     "status":"opened",
     "readStatus":"read",
     "timeAgoElement":"2015-08-20T16:58:20.000-04:00",
     "createdAt":"June 16th, 2015 20:00",
     "user":
            {
               "id":4
            }
    }
   ]}

The problem I get is that Ember-data is able to add my data to the store but I get this error :

Passing classes to store methods has been removed. Please pass a dasherized string instead of undefined

I have read these posts : #272 and #261

Is it a problem with the JSON response?

Thank you. I have been using ember-data for quite a bit of time and never encountered this error before switching to ember 2.0.1 and ember-data 2.0.0


#2

The solution I found is adding a serializer providing the following configuration:

export default DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
  attrs: {
    exchange: {
      embedded: 'always',
      serialize: 'id'
    }
  },
...

My model attribute id exchange and I have a DS.belongsTo relationship. With hasMany I guess you could use something like this:

//serializers/user.js

export default DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
  attrs: {
    conversation: {
      embedded: 'always',
      serialize: 'ids'
    }
  },
...

Access request params from query params within a route
#3

I think this error comes up when you have a relationship for a property and the data coming in from the server has an embedded record for that property when using the RESTSerializer. For example:

// models/person.js
export default DS.Model.extend({
  home: DS.belongsTo()
});

If your JSON looks like this:

{
  "id": 1,
  "name: "David",
  "home": {
      "id": 4,
      "location": "Hawaii"
  }
}

“home” should only contain the ID, if following the RESTSerializer conventions.