2
votes

here is a working jsbin: http://emberjs.jsbin.com/EnOqUxe/71/edit

What i´d like to have is there the company doesn´t need any reference to the person.

non working code

App.Company.FIXTURES = [
  { id: 1, name: 'Microsoft'},
  { id: 2, name: 'Apple'}
];

App.Person.FIXTURES = [
  { id: 1,  name: 'Steve Jobs', company:2},
  { id: 2,  name: 'Bill Gates', company:1},
  { id: 3,  name: 'Steve Ballmer', company:1}
];

How can i achieve this?

thank you

1

1 Answers

0
votes

You're practically there. You just need to fix up the models a bit:

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

App.Person = DS.Model.extend({
  name: DS.attr('string'),
  company: DS.belongsTo('company', {async:true})
});

And change your model hook, since now you link to companies through people, not people through companies.

App.IndexRoute = Ember.Route.extend({
  model: function() {
    return this.store.find('person');
  }
});

http://emberjs.jsbin.com/EnOqUxe/72/edit