Question

I'm learning EmberJS and need some help.

I have two models: Catalog and CatalogCourses. Catalog has many CatalogCourses. I'm just trying to test this relationship with some fixtures.

When I load a record of Catalog the relationship fixtures (CatalogCourses) doesn't load. I've been stuck on this for a couple hours, and I think it should be simple to do this, so I'm asking for your help.

Here are the models:

App.Catalog = DS.Model.extend({
  year: DS.attr('string'),
  catalogCourses: DS.hasMany('catalog_course')
});

App.CatalogCourse = DS.Model.extend({
  catalog: DS.belongsTo('catalog')
});

And here are the Fixtures:

App.Catalog.FIXTURES = [
  {
    id: 1,
    year: '2014',
    catalog_courses: [ 1 ]
  }
];

App.CatalogCourse.FIXTURES = [
  {
    id: 1,
    catalog: 1
  }
];

And here is a Fiddle of me trying to simply list that relationship: http://jsfiddle.net/6Evrq/75/

I'm using ember v1.5.0, ember-data v1.0.0-beta.7, handlebars v1.3.0 and jQuery 1.11.0

I tried using the {async: true} option aswell, but the problem persists.

Any thoughts?

Was it helpful?

Solution

Your problem is just in your fixtures. You name your model attribute catalogCourses, yet in your fixture setup you use catalog_courses. If you change catalog_courses to catalogCourses in your fixture setup, it works.

Mind you that for using fixtures with relations, you need to use the { async: true } flag on the relationship definition in your models.

See this jsbin with a working example: http://emberjs.jsbin.com/gedew/2/edit

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top