1
我有一個Rails API,我試圖拉入Ember中的記錄,並且在工作時,我的嵌套模型不是。我有一個Employee
是belongs_to
一個Location
並創造像這樣一個串行:Rails + Ember:嵌套模型格式不正確
class API::EmployeeSerializer < ActiveModel::Serializer
attributes :id, :name, :phone, :email, :manager, :terminated, :location
belongs_to :location
end
,輸出:
{"employee":
{"id":19,"name":"John Abreu","phone":"","email":"","manager":false,"terminated":false,"location":
{"name":"Peabody","id":2}
}
}
和我的灰燼應用程序通過拉這樣的:
進口灰燼從'餘燼';
export default Ember.Route.extend({
model() {
return this.store.findAll('employee')
}
});
,但我打我的錯誤,當我遇到哈希location
部分。我得到以下內容:
> 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.
我該如何解決這個問題?我已經有一個LocationSerializer
有:
class LocationSerializer < ActiveModel::Serializer
attributes :id, :phone, :address, :name
end
嘗試改變':location'到':location_id'在屬性 – Pavan
沒有運氣它正確地包含了':location_id',但仍然包含錯誤發生位置的'location'哈希 –