Encountered "1" in payload, but no model was found for model name "1" (resolved model name using (unknown).modelNameFromPayloadKey("1"))

Hi,

I’m currently working on a todoApp using Rails API as backend and EmbersJs as front. I want everything to be displayed on the rootURL.

I got this error from my firefox console : Encountered “1” in payload, but no model was found for model name “1” (resolved model name using (unknown).modelNameFromPayloadKey(“1”)).

I dont understand where that could come from.

here’s my app/models/todo.js : import DS from ‘ember-data’;

export default DS.Model.extend({
  title: DS.attr('string'),
  isCompleted: DS.attr('boolean')
});

my app/routes/application.js:

import Route from '@ember/routing/route';

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

And my app/templates/application.hbs :

<h1>Test micro</h1>

<ul>
  {{#each model as |todo|}}
    <li>{{todo.title}} Fait ? :{{todo.isCompleted}}</li>
  {{/each}}
</ul>
{{outlet}}

my rails-api/serializers/todo_serializer.rb :

class TodoSerializer < ActiveModel::Serializer
  attributes :id, :title, :isCompleted
end

my `rails-api/controllers/todos_controller.rb:

class TodosController < ApplicationController
  def index
    render json: Todo.all
  end
end

and my rails-api/models/todo

class Todo < ActiveRecord::Base
end

As i’m new on Ember, maybe am i looking at the wrong place, but if someone have an idea, that would be awesome ! If you need any further informations, just let me know.

Without seeing your payload, it looks like you’re missing a top level key (todos on line 2 below) on the POJO. For example, if you were using REST (that’s what my company uses), you should see something like:

{
    "todos": [
        {
            "id": 1,
            "title": "do stuff",
            "isCompleted": true
        },
        {
            "id": 2,
            "title": "do more stuff",
            "isCompleted": false
        }
    ]
}

We actually wrote standards to help with this when writing/consuming APIs, but note that we’re using REST. If you’re using JSON API (Ember Data default), you’ll need your payloads to match that format.

Yes indeed, a few research after asking this question gave me the right answer. I did it now, even if I have other issue for now :smiley: