Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error: You need to pass a model name to the store's modelFor method

Using Ember 2.6.0

Have the following routes defined:

Router.map(function() {
  this.route('brands');
  this.route('brand', {path: '/brands/:brand_id'});
});

The model for brand is:

export default Model.extend({
  name: attr('string'),
  description: attr('string'),
  dateCreated: attr('date'),
  lastUpdated: attr('date'),
  regions: hasMany('region')
});

And the model for region is:

export default Model.extend({
  name: attr('string'),
  dateCreated: attr('date'),
  lastUpdated: attr('date'),
  brand: belongsTo('brand')
});

Now, when trying to access /brands I am doing this in the route:

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

I am getting the following error:

You need to pass a model name to the store's modelFor method

This worked prior to adding the brand route and region relationships. Brand is the parent, so I'm not sure why this isn't working.

UPDATE:

Removing regions: hasMany('region') from the brand model allows things to work again. Not sure why it isn't working with the defined relationship.

like image 526
Gregg Avatar asked Mar 11 '23 22:03

Gregg


1 Answers

So it turns out I had to create serializers for each object. For brand I have:

import RESTSerializer from 'ember-data/serializers/rest';
import DS from 'ember-data';

export default RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
  attrs: {
      regions: {embedded: 'always'}
  }
});

And for region I have:

import RESTSerializer from 'ember-data/serializers/rest';

export default RESTSerializer.extend({
});

Technically, it works without the region serializer but I get a warning that ember couldn't find regions inside the region model. I may submit a ticket to ember to suggest not having to create an empty RESTSerializer just to avoid this warning.

like image 58
Gregg Avatar answered May 16 '23 08:05

Gregg