2013-04-03 37 views
0

我使用的鐵軌/燼/燼數據,並試圖側面插入多個關聯。如何使用belongs_to關聯來裝載多個模型實例?

App.Plan = DS.Model.extend({ 
    schedule: DS.belongsTo('App.Schedule'), 
    questions: DS.hasMany('App.Question') 
}); 

App.Schedule = DS.Model.extend({ 
    plan: DS.belongsTo('App.Plan'), 
    start: DS.attr('date'), 
}); 

App.Question = DS.Model.extend({ 
    name: DS.attr('string') 
}) 

和下面的鐵軌串行:

class PlanSerializer < ActiveModel::Serializer 
    embed :ids, :include => true 

    attributes :id, :owner_id 

    has_one :schedule 
    has_many :questions 
end 

class QuestionSerializer < ActiveModel::Serializer 
    attributes :id, :name, :plan_id 
end 

class ScheduleSerializer < ActiveModel::Serializer 
    attributes :id, :start, :time_established, :plan_id 
end 

,我發現了以下錯誤:

Uncaught Error: assertion failed: Your server returned a hash with the 
key schedules but you have no mapping for it 

什麼 '映射' 這是指的?我試圖把所有信息上下貫通/plans.json

如果我註釋掉所有的日程安排的東西,計劃/加載的問題罰款。但我無法讓時間表的行爲。

我收集這個事做與我嵌入多張時間表(複數),但該計劃的關聯是奇異的事實。我想也許這與客戶端的多元化有關,並試圖:

DS.RESTAdapter.configure("plurals", { 
    schedule: 'schedules' 
}); 

...但沒有幫助。很確定這不是問題,因爲它不是一個不規則的多元化。

是否有事可做與返回的JSON的順序?

這個JSON是迴歸的時間表,問題,那麼計劃。雖然計劃是'根'節點。

任何想法?由於

回答

0
DS.RESTAdapter.configure('App.Schedule', 
    {sideloadAs: 'schedules'} 
); 
相關問題