FixtureAdapter and DS.hasMany

Hey - I’ve been building out a sample application with Ember over the past few days and am running into a fairly large issue with the FixtureAdapter and a hasMany relationship.

I’m building a simple time tracking utility and want to be able to access multiple TimeEntry records via a Task.

There’s no trouble loading the Task through it’s belongsTo relationship from TimeEntry, but going vice versa and getting the manyArray of TimeEntry objects doesn’t work.

Here’s the most simple implementation of the models. I’m just wondering if anyone has experience with getting this to work… Am I making some dumb mistake, or does this just plain not work?

App.Task = DS.Model.extend({
  name: DS.attr(),
  timeEntries: DS.hasMany('time_entry'),
});

App.Task.FIXTURES = [
  {
    id: 1,
    name: 'Tracking time.',
    time_entries: [1,2]
  }
];




App.TimeEntry = DS.Model.extend({
  startTime: DS.attr('date'),
  endTime: DS.attr('date'),
  task: DS.belongsTo('task')
});


App.TimeEntry.FIXTURES = [
  {
    id: 1,
    startTime: "2013-11-29T04:52:17.249Z",
    endTime: "2013-11-29T06:52:17.249Z",
    task: 1
  }, {
    id: 2,
    startTime: "2013-11-22T06:52:17.249Z",
    endTime: "2013-11-21T06:52:17.249Z",
    task: 1
  }
];

Any help would be SO appreciated.

Thanks!

I don’t have experience with this personally, but from what I know FixtureAdapter is very limited in its abilities. Look through issues in Ember Data that include hasMany keyword ( if you haven’t already done so ).

Yeah - I guess I was hoping for a miracle with the 1.0.0-beta reboot.

It works pretty well with RESTAdapter, but this is another story.

Thanks!

I was having the same problem.

Try time_entries: DS.hasMany('time_entry', {async: true})

I stumbled on the async option somewhere along the way.

I can vouch to seeing the same behavior. When I add a hasMany relationship, I get an error as follows (if I try to access the children from the parent):

Assertion failed: You looked up the ‘items’ relationship on ‘<(subclass of DS.Model):ember291:1>’ but some of the associated records were not loaded. Either make sure they are all loaded together with the parent record, or specify that the relationship is async (DS.hasMany({ async: true }))

and adding {async: true} only gets rid of the error. The child items still aren’t accessible.

note: I’m using ember-app-kit and doing reopenClass on the the models to define the FIXTURES

var Group = DS.Model.extend({
  items: DS.hasMany('item')
}); 

Group.reopenClass({
  FIXTURES: [ { ... } ]
});