0
votes

I'm using rails / ember / ember-data, and trying to sideload multiple associations.

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')
})

and the following rails serializers:

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

I'm getting the following error:

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

What 'mapping' is this refering to? I'm trying to pull all info down through /plans.json

If I comment out all of the Schedule stuff, the plans/questions load fine. But I just can't get the schedules to behave.

I gather this has something to do with the fact I'm embedding mulitple scheduleS (plural) but the plan association is singular. I thought maybe this had to do with pluralization on the client side and tried:

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

... but didn't help. Pretty sure that's not the issue, as it's not an irregular pluralization.

Does it have something to do with the order of the returned json?

this json is returning schedules, questions, then the plans. Though the plans are the 'root' node.

Any ideas? Thanks

1

1 Answers

0
votes
DS.RESTAdapter.configure('App.Schedule',
  {sideloadAs: 'schedules'}
);