I have a Rails API and I am trying to pull in records in Ember and while its working, my nested model is not. I have an Employee
that belongs_to
a Location
and have created a serializer like so:
class API::EmployeeSerializer < ActiveModel::Serializer
attributes :id, :name, :phone, :email, :manager, :terminated, :location
belongs_to :location
end
which outputs:
{"employee":
{"id":19,"name":"John Abreu","phone":"","email":"","manager":false,"terminated":false,"location":
{"name":"Peabody","id":2}
}
}
and my ember app pulls this in through:
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.findAll('employee')
}
});
but I hit my error when I encounter the location
portion of the hash. I get the following:
> Assertion Failed: Ember Data expected the data for the location
> relationship on a <employee:19> to be in a JSON API format and include
> an `id` and `type` property but it found {name: Peabody, id: 2}.
> Please check your serializer and make sure it is serializing the
> relationship payload into a JSON API format.
How can I correct this? I already have a LocationSerializer
that has:
class LocationSerializer < ActiveModel::Serializer
attributes :id, :phone, :address, :name
end
Aucun commentaire:
Enregistrer un commentaire