2
votes

I have this error when try call rest api : Encountered "companies" in payload, but no model was found for model name "company"

http://localhost:9000/api/insurance/travel/companies

Call example :

var companies = this.store.find("insurance/travel/company");

Model :

export default DS.Model.extend({
    name: DS.attr('string'),
    url: DS.attr('string'),
    logoUrl: DS.attr('string'),
    contactUrl: DS.attr('string'),
    moreUrl: DS.attr('string'),
    about: DS.attr('string')
})

JSON Example :

{
    "companies": [
        {
            "id": "id1",
            "name": "test",
            "url": "http://google.com",
            "logoUrl": "http://google.com",
            "contactUrl": "http://google.com",
            "moreUrl": "http://google.com",
            "about": "about text"
        },
        {
            "id": "id2",
            "name": "test 2",
            "url": "http://google.com",
            "logoUrl": "http://google.com",
            "contactUrl": "http://google.com",
            "moreUrl": "http://google.com",
            "about": "about text"
        }
    ]
}
1
Ember must not be recognizing your Model as the company model. Where is your model file (assuming you are using ember-cli).Steve H.
I'm having the same problem...JonathanBristow
Facing same issue hereJagdish
I have resolved this issue. There was spelling mistake in API's code for return JSON.Jagdish

1 Answers

0
votes

Create an adapter and inject a inflector

import DS from 'ember-data';
import Ember from 'ember';

var inflector = Ember.Inflector.inflector;
inflector.uncountable('company');

export default DS.RESTAdapter.extend({});

It worked for me