Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does DS.FixtureAdapter has sideload support?

I'm using DS.FixtureAdapter and can't get related entries using DS.belongsTo

App.User = DS.Model.extend({
    login: DS.attr('string'),
    profile: DS.belongsTo('App.Profile')
});

App.Profile = DS.Model.extend({
    fullname: DS.attr('string'),
    address: DS.attr('string'),
    user: DS.belongsTo('App.User')
});

App.Router.map(function() {
    this.resource('user', { path: ':user_id' });
});

App.UserRoute = Ember.Route.extend({
  model: function(params) {
    return App.User.find(params.user_id)
  }
});

Is it only a feature of Rest Adapter?

update

The fixture data is something like this:

something like this:

App.User.FIXTURES = [
    {
      id: 1,
      login: "marlus",
      profile: 1
    }
];

App.Profile.FIXTURES = [
    {
      id: 1,
      fullname: "Marlus Araujo",
      address: "Rio",
      user: 1
    }
];
like image 865
Marlus Araujo Avatar asked Nov 04 '22 00:11

Marlus Araujo


2 Answers

The latest version of Ember Data (1.0.0-beta4), has a new syntax for configuring a model with a fixture adapter.

App.UserAdapter = DS.FixtureAdapter.extend();

App.User.FIXTURES = [{
    id: 1, firstName: 'Bob', lastName: 'Roberts'
}];

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

App.UserRoute = Ember.Route.extend({
    model: function() {
        return this.store.find('user', params.user_id);
    }
});
like image 92
rxgx Avatar answered Nov 08 '22 05:11

rxgx


Try:

return this.get('store').find('App.User', params.user_id);

Also, this could be helpful: http://emberjs.com/guides/models/finding-a-record/

like image 24
ObviousCat Avatar answered Nov 08 '22 06:11

ObviousCat